Cache by-type lookups in DefaultListableBeanFactory (SPR-6870)

[SPR-9448] Backport "Cache by-type lookups in DefaultListableBeanFactory" Created: 27/May/12  Updated: 05/Aug/12  Resolved: 27/Jun/12

Status: Resolved
Project: Spring Framework
Component/s: Core
Affects Version/s: 2.5.6
Fix Version/s: 3.1.2

Type: Backport Priority: Major
Reporter: Chris Beams Assignee: Chris Beams
Resolution: Complete Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Days since last comment: 6 years, 7 weeks, 5 days ago
Last commented by a User: true
Last updater: Francisco Lozano

Comment by Chris Beams [ 27/Jun/12 ]
commit d24d535c1db843403981cc2c3423e456046d5e69
Author: Chris Beams <>
Commit: Chris Beams <>

    Cache by-type lookups in DefaultListableBeanFactory
    Prior to this change, by-type lookups using DLBF#getBeanNamesForType
    required traversal of all bean definitions within the bean factory
    in order to inspect their bean class for assignability to the target
    type. These operations are comparatively expensive and when there are a
    large number of beans registered within the container coupled with a
    large number of by-type lookups at runtime, the performance impact can
    be severe. The test introduced here demonstrates such a scenario clearly.
    This performance problem is likely to manifest in large Spring-based
    applications using non-singleton beans, particularly request-scoped
    beans that may be created and wired many thousands of times per second.
    This commit introduces a simple ConcurrentHashMap-based caching strategy
    for by-type lookups; container-wide assignability checks happen only
    once on the first by-type lookup and are afterwards cached by type
    with the values in the map being an array of all bean names assignable
    to that type. This means that at runtime when creating and autowiring
    non-singleton beans, the cost of by-type lookups is reduced to that of
    Issue: SPR-9448
    Backport-Issue: SPR-6870
    Backport-Commit: 4c7a1c0a5403b35dd812dae1f2a753538928bb32
Comment by Francisco Lozano [ 05/Aug/12 ]

This backport has been like an early X-mas present, thanks a lot!

Generated at Sat Sep 22 12:59:02 UTC 2018 using JIRA 7.9.2#79002-sha1:3bb15b68ecd99a30eb364c4c1a393359bcad6278.