spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
55.22k stars 37.57k forks source link

Performance improvement in HashMapCachingAdvisorChainFactory [SPR-31] #4766

Closed spring-projects-issues closed 20 years ago

spring-projects-issues commented 20 years ago

Steven Bazyl opened SPR-31 and commented

I did some profiling of the aspect support in Spring and found that the HashMapCachingAdvisorChainFactory was taking up a significant portion of the time. In particular, most of the time was spent computing the hashcode of the Method object used as the key (ends up calling getName() on the class which is native.) This accounted for about 35% of the execution time of the test.

I switched from HashMap to IdentityHashMap to take advantage of the fact that the Method instances are cached along with the class and the result was a big boost :) Please incorporate this into the next release. Spring's runtime AOP support is still to slow for me at the moment, but I expect it will get better over time.


Affects: 1.0 M4

spring-projects-issues commented 20 years ago

Rod Johnson commented

Thanks for the report. I've checked this in. As you say, it produces a big performance gain. I was aware that Method.hashCode() was a problem, but hadn't thought of that extremely simple way of getting around the problem. The fix is 1.3-compatible, as it tries to create an IdentityHashMap using reflection, and falls back to HashMap if it can't (in 1.3).

Further performance improvements are likely, although the AOP framework performs well for its primary intended use (alternative to EJB). If you're interested in pursuing further performance improvements, drop me an email and we can discuss it.

Regards, Rod