I would like to know if any hard data exist on the cost of using a Filter ?
For instance, between using heritage on servlet for sharing a behavior, or using a filter ?
Thanks,
Antoine
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’ll be surprised if someone can post hard data. And even if they do, it most likely won’t be pertinent to you, because the numbers will depend on what’s being done in the filter. It’s also likely to fall into the premature optimization category – it isn’t likely to matter unless you really screw something up badly.
I’ll assume that “heritage” means “inheritance” and say that filters are a far better solution. You have the option of turning them off and on in configuration.
Filters are decorators or aspects for HTTP requests. Since those are well-respected, tried-and-true patterns, why would they not be useful and safe for use by servlets?
I’d say your concerns are overblown.
With that said, I would not recommend building such a long, complex filter chain that performance does become an issue. You could end up with a problem if you do compression, logging, performance metrics, etc. and end up with a chain of a dozen filters.