I've a Servlet filter which performs the following type cast:
HttpServletRequest httpRequest = (HttpServletRequest) req;
At present my filter is responsible for two tasks that would be better separated into two filters. If I'd split the logic into two filters I'd need two casts.
What is the performance impact of such a cast? Is it worth to accept this performance degradation for a better architecture?
What is the performance impact of such a cast?
As compared to handling a HTTP request? Absolutely none. If you were doing it in a deeply nested loop that does little else it might matter, but not when it's done once for a task that involves things that are literally millions of times more work (like doing DB requests or accessing the harddisk).
Performance impact will be negligible (compared to the total work done). Java does a lot of casting, like in the collection framework, hence the engineers already optimized it well. An additional casting won't change much, besides, readability (maintainability?) is more important.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With