Skip to content

Backport "Cache by-type lookups in DefaultListableBeanFactory" [SPR-9448] #14083

Closed

Description

@spring-projects-issues

Chris Beams opened SPR-9448 and commented


Affects: 2.5.6

This issue is a backport sub-task of #11536

1 votes, 4 watchers

Activity

  1. spring-projects-issues commented on Jun 27, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    commit d24d535c1db843403981cc2c3423e456046d5e69
    Author: Chris Beams <[email protected]>
    Commit: Chris Beams <[email protected]>
    
        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
        ConcurrentHashMap#get.
        
        Issue: SPR-9448
        Backport-Issue: SPR-6870
        Backport-Commit: 4c7a1c0a5403b35dd812dae1f2a753538928bb32
    
  2. spring-projects-issues commented on Aug 5, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Francisco Lozano commented

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

  3. added
    in: core
    on Jan 11, 2019
  4. added this to the 3.1.2 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: core

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions