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

Poor Performance with lots of Prototype Scoped Beans



    • Last commented by a User:


      We are seeing a pretty substantial performance hit with the creation of large quantities of prototype-scoped beans in the 3.1.x branch versus 3.0.x (and 2.5.6)

      In our example, we have call context.getBean() with a bean consisting of 2 levels of nested bean referenced, in a pretty large loop.

      3.0.7: 40604ms
      3.1.2: 685150ms

      The only difference between these runs is the version of the spring dependencies.

      After profiling using YourKit, I found the hotspots in 3.1.x to be in the following places:

      org.springframework.beans.TypeConverterDelegate: This seems to be the bigger problem.
      The changes introduced in 3.1 (specifically, in commit https://github.com/SpringSource/spring-framework/commit/6f146737f475828b6d765784017773378c2c4922) to findDefaultEditor() end up (expensively) initializing an editor registry every time this is called. Since we get here each time we apply a property on every bean creation, this really adds up. Previously, the commented-out code ended up shortcutting this. I found that replacing the commented out code (the part that relied on the now-removed PropertyTypeDescriptor/PropertyDescriptor with static use of PropertyEditorManager.findEditor(), cuts down on the slowness considerably, at the expense of relying on java.beans - which a few commit comments seem to indicate is something to be avoided for better platform compatibility.

      org.springframework.core.convert.Property: This also seems to be a problem.
      The overhead of the annotation parsing via reflection is already noted in SPR-9343 - but that issue doesn't seem to mention this example. My profiling is showing that this is being constructed for every property found on every bean being created. With lots of prototype beans - this comes to light pretty quickly. Perhaps if ReflectionUtils used a similar caching strategy to apache commons-beanutils PropertyUtilsBean for annotations, this performance hit could be mitigated.


          Issue Links



              juergen.hoeller Juergen Hoeller
              kmudrick Kevin Mudrick
              Last updater:
              Spring Issues Spring Issues
              0 Vote for this issue
              6 Start watching this issue


                Days since last comment:
                3 years, 24 weeks, 5 days ago