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

Major Performance Problem in ApplicationContext Creation and Prototype Bean Lookup by Type

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Duplicate
    • Affects Version/s: 3.1.1
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
    • Last commented by a User:
      true

      Description

      In version 3.1.1 of the springframework, the creation of the application context and the lookup of beans by type, in particular the lookup of prototype beans is extremely slow (factor 10).
      The same creation and lookup process in spring 3.0.6 was significantly faster.
      The definition of the application context is done through java based bean configuration.

      Therefore we created a sample programm which can be used to reproduce the problem (program together with a gradle build file is attached, gradle run executes the test).
      This application uses javasssist to create 100 bean classes. Each bean class has 5 autowired bean properties. The bean properties are generated, such that no cyclic dependencies occur. Finally a configuration class containing the generated beans is constructed and loaded. All beans are created as singletons except one bean which has been created as prototype scope.
      After the application context is loaded a single bean is looked up from the application context 100 times. In the first case this is done with a bean of scope singleton. In the second case this is done with a bean of scope prototype.
      The same tests was issued on spring 3.1.1 and spring 3.0.6

      The results are as follows:

      ==== Spring 3.1.1 ====

      SingletonBean:
      ==============
      StopWatch 'SpringPerformanceTest': running time (millis) = 17004; [settingUpApplicationContext] took 15177 = 89%; [retrievingBeans] took 1827 = 11%

      PrototypeBean:
      ==============
      StopWatch 'SpringPerformanceTest': running time (millis) = 24400; [settingUpApplicationContext] took 13126 = 54%; [retrievingBeans] took 11274 = 46%

      ==== Spring 3.0.6 ====

      SingletonBean:
      ==============
      StopWatch 'SpringPerformanceTest': running time (millis) = 3110; [settingUpApplicationContext] took 2654 = 85%; [retrievingBeans] took 456 = 15%

      PrototypeBean:
      ==============
      StopWatch 'SpringPerformanceTest': running time (millis) = 3163; [settingUpApplicationContext] took 1790 = 57%; [retrievingBeans] took 1373 = 43%

        Issue Links

          Activity

          Hide
          barni Stephan Andresen added a comment -

          We have the same problem with 3.0.7.RELEASE everthing was fine, with 3.1.0.RELEASE the lookup is very slowly (about factor 6)

          Show
          barni Stephan Andresen added a comment - We have the same problem with 3.0.7.RELEASE everthing was fine, with 3.1.0.RELEASE the lookup is very slowly (about factor 6)
          Hide
          cbeams Chris Beams added a comment -

          Robert, thanks for the great reproduction project! You'll be glad to know this issue is now fixed with the resolution of SPR-6870.

          Here are the results...

          ==== 3.0.6 ====
          StopWatch 'SpringPerformanceTest': running time (millis) = 1844; [settingUpApplicationContext] took 1701 = 92%; [retrievingBeans] took 143 = 8%
          StopWatch 'SpringPerformanceTest': running time (millis) = 2083; [settingUpApplicationContext] took 1171 = 56%; [retrievingBeans] took 912 = 44%
           
          ==== 3.1.1 ====
          StopWatch 'SpringPerformanceTest': running time (millis) = 10928; [settingUpApplicationContext] took 9658 = 88%; [retrievingBeans] took 1270 = 12%
          StopWatch 'SpringPerformanceTest': running time (millis) = 16974; [settingUpApplicationContext] took 9145 = 54%; [retrievingBeans] took 7829 = 46%
           
          ==== 3.2.0.BUILD-SNAPSHOT ====
          StopWatch 'SpringPerformanceTest': running time (millis) = 3793; [settingUpApplicationContext] took 3766 = 99%; [retrievingBeans] took 27 = 1%
          StopWatch 'SpringPerformanceTest': running time (millis) = 2934; [settingUpApplicationContext] took 2829 = 96%; [retrievingBeans] took 105 = 4%

          Cheers!

          Show
          cbeams Chris Beams added a comment - Robert, thanks for the great reproduction project! You'll be glad to know this issue is now fixed with the resolution of SPR-6870 . Here are the results... ==== 3.0.6 ==== StopWatch 'SpringPerformanceTest': running time (millis) = 1844; [settingUpApplicationContext] took 1701 = 92%; [retrievingBeans] took 143 = 8% StopWatch 'SpringPerformanceTest': running time (millis) = 2083; [settingUpApplicationContext] took 1171 = 56%; [retrievingBeans] took 912 = 44%   ==== 3.1.1 ==== StopWatch 'SpringPerformanceTest': running time (millis) = 10928; [settingUpApplicationContext] took 9658 = 88%; [retrievingBeans] took 1270 = 12% StopWatch 'SpringPerformanceTest': running time (millis) = 16974; [settingUpApplicationContext] took 9145 = 54%; [retrievingBeans] took 7829 = 46%   ==== 3.2.0.BUILD-SNAPSHOT ==== StopWatch 'SpringPerformanceTest': running time (millis) = 3793; [settingUpApplicationContext] took 3766 = 99%; [retrievingBeans] took 27 = 1% StopWatch 'SpringPerformanceTest': running time (millis) = 2934; [settingUpApplicationContext] took 2829 = 96%; [retrievingBeans] took 105 = 4% Cheers!
          Hide
          speedskater Robert Binna added a comment -

          Thanks Chris, for the fast and nice fix.

          Show
          speedskater Robert Binna added a comment - Thanks Chris, for the fast and nice fix.

            People

            • Assignee:
              cbeams Chris Beams
              Reporter:
              speedskater Robert Binna
              Last updater:
              Trevor Marshall
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                5 years, 7 weeks, 3 days ago