-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Closed
Closed
Copy link
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchesAn issue that has been backported to maintenance branchestype: enhancementA general enhancementA general enhancement
Milestone
Description
Collaborator
Issue body actions
Juergen Hoeller opened SPR-12250 and commented
The current BeanFactory.getBean
algorithm is optimized towards singleton access, always checking the singleton map for a quick check before proceeding with scope handling.
Lock-free access to non-singleton beans is equally important and seems to be easy enough to achieve: through a check on registered singleton names before going into the lock on the singleton map.
Affects: 3.2.11, 4.0.7, 4.1 GA
Issue Links:
- AbstractBeanFactory#markBeanAsCreated performance issue due to lock contention [SPR-9780] #14414 AbstractBeanFactory#markBeanAsCreated performance issue due to lock contention
- Non-singleton beans performance issue [SPR-9819] #14452 Non-singleton beans performance issue
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchesAn issue that has been backported to maintenance branchestype: enhancementA general enhancementA general enhancement
Type
Projects
Relationships
Development
Select code repository
Activity
spring-projects-issues commentedon Sep 25, 2014
Juergen Hoeller commented
In fact, after #14452, all that we still do is a quick check on the "singletonObjects"
ConcurrentHashMap
and an equally efficient "isSingletonCurrentlyInCreation" check, against aConcurrentHashMap
as well, both with plain bean name String keys. This is very efficient and hard to beat with any singleton names check on an additional data structure.Let's use this issue as an opportunity for comments towards further improvements, if there are any ideas.
Juergen
spring-projects-issues commentedon Oct 6, 2014
Juergen Hoeller commented
As discussed in #14414, we should be able to optimize
markBeanAsCreated
performance through the use ofputIfAbsent
.Juergen
spring-projects-issues commentedon Oct 6, 2014
Bernhard Frauendienst commented
Unfortunately
putIfAbsent
is not optimized that way, it will also lock the segment (note the synchronized block in ConcurrentHashMap.java:1027 and theonlyIfAbsent
check in ConcurrentHashMap.java:1037).AFAICT the only way to reduce lock contention would be to do a
get
/containsKey
beforehand and return early if it returns true. This creates the possibility of a race condition in which multiple threads actually put the value in the map, but this does not change semantics and is still an improvement to the current situation wrt lock contention.spring-projects-issues commentedon Oct 6, 2014
Juergen Hoeller commented
Good point. Addressed this through an explicit
contains
check before theadd
call now - forAbstractBeanFactory.alreadyCreated
as well asAbstractAutoProxyCreator.earlyProxyReferences
.Juergen