Summary: | Use of new Boolean() has performance implications | ||
---|---|---|---|
Product: | Taglibs | Reporter: | Heath Chiavettone <hchiavettone> |
Component: | Standard Taglib | Assignee: | Tomcat Developers Mailing List <dev> |
Status: | RESOLVED FIXED | ||
Severity: | enhancement | ||
Priority: | P3 | ||
Version: | 1.0 | ||
Target Milestone: | --- | ||
Hardware: | All | ||
OS: | other |
Description
Heath Chiavettone
2003-02-04 19:00:31 UTC
Do you have some evidence that this leads, in practice, to a performance- problem on any real-world system. The change you're suggesting is minor, so I can just make it as soon as I get a chance, but I'm not inclined to go out of my way to intuit things about system performance without hard evidence. My impression is that any legitimate JIT knows how to optimize this kind of code; object creation is emphatically *not* expensive on nearly all real-world JITs, and code is often made complex out of a mistaken desire to avoid it! I agree with Shawn the JITs should take care of these kinds of optimization. In fact, if they do, then your approach would penalize the performance, as it would require an extra method call. On the other hand, such static function already exists in JDK 1.4.2: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Boolean.html#valueOf(boolean) The fact that this function exists suggests that creating new Booleans in fact a decreases performance. If JSTL depended on JDK 1.4.2, we could easily fix this by using replacing the occurrences of "new Boolean(x)" to "Boolean.valueOf(x)", but unfortunately that's not the case. Another option would be Boolean.valueOf(""+x), as JDK 1.3.x has a valueOf(String) method. Just my 2 cents, Felipe Did a general audit and substituted static values where Boolean objects were created where appropriate. Changes were made to standard HEAD and available in the nightly build and will be available in the upcoming Standard 1.1.1 release. I agree with Shawn and Felipe's assessment that the JIT should take care of this type of optimization so therefore the static helper method won't be implemented. I believe that the added method call may penalize performance. |