Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-13655

AbstractAutoProxyCreator.getCacheKey generate lots of String garbage

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 4.2.2
    • Fix Version/s: 4.2.3
    • Component/s: Core:AOP
    • Labels:
    • Last commented by a User:
      false

      Description

      Current implementation of getCacheKey uses string concatenation: https://github.com/spring-projects/spring-framework/blob/master/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java#L306-L308

      This leads to two problems:
      1) Excessive heap garbage due to throw-away string creation
      2) Excessive CPU due to computing hash code for the newly created strings.

      In our spring context present 1200+ beans and ~20 beanPostProcessors as result E2E spenario for 30 minute generate ~300GB char[]

      It our problem that legacy part of system use BeanFactory.getBean instead of inject dependency correctly. But problem described above also affect application start time because spring for inject dependency also do getBean by Class and as result spring for each class iterate by all beans in context and generate cache key like:

      	protected Object getCacheKey(Class<?> beanClass, String beanName) {
      		return beanClass.getName() + "_" + beanName;
      	}
      

        Issue Links

          Activity

          Hide
          gordiychuk Vladimir Gordiychuk added a comment -

          I prepare pull request and submit it right now

          Show
          gordiychuk Vladimir Gordiychuk added a comment - I prepare pull request and submit it right now
          Show
          gordiychuk Vladimir Gordiychuk added a comment - Pull request https://github.com/spring-projects/spring-framework/pull/913
          Hide
          juergen.hoeller Juergen Hoeller added a comment -

          After some further consideration, AbstractAutoProxyCreator uses a prefixed bean name as its cache key now: either with the FactoryBean prefix "&" or just the plain bean name, depending on a type check. We therefore align it with our own recommendation in the BeanPostProcessor.postProcessAfterInitialization callback javadoc.

          Juergen

          Show
          juergen.hoeller Juergen Hoeller added a comment - After some further consideration, AbstractAutoProxyCreator uses a prefixed bean name as its cache key now: either with the FactoryBean prefix "&" or just the plain bean name, depending on a type check. We therefore align it with our own recommendation in the BeanPostProcessor.postProcessAfterInitialization callback javadoc. Juergen

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              gordiychuk Vladimir Gordiychuk
              Last updater:
              St├ęphane Nicoll
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                2 years, 15 weeks, 1 day ago