Avoid lock congestion in ConcurrentReferenceHashMap#36293
Merged
jhoeller merged 1 commit intospring-projects:mainfrom Feb 11, 2026
Merged
Avoid lock congestion in ConcurrentReferenceHashMap#36293jhoeller merged 1 commit intospring-projects:mainfrom
jhoeller merged 1 commit intospring-projects:mainfrom
Conversation
…ion of computeIfAbsent and computeIfPresent Signed-off-by: Christian Schuster <christian@dnup.de>
16ab7e0 to
cbac801
Compare
Contributor
|
Thanks for the PR - merged for 7.0.4 now. I'll backport this to 6.2.16 as well. Both releases are scheduled for tomorrow. This tradeoff is entirely feasible for |
Contributor
|
On a related note, we revised this for 7.0.4 toward local annotation caching within our |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After updating from Spring Framework v6.2.11 to v6.2.15, we observed heavy lock congestion even under moderate load. The following stacktrace shows the culprit:
Most of the time, the call to
ConcurrentReferenceHashMap.computeIfAbsent(...)is read-only and doesn't need the lock.The implementations of
computeIfAbsent(...)andcomputeIfPresent(...)have been added in v7.0.0 with commit 0552cdb and backported to v6.2.13 with commit 12dd758.Please note that this issue is different from the one described in gh-35944, because it doesn't involve a call to
AnnotationTypeMappings$Cache.get(...).This PR adds lock-free checks to these methods to avoid locking in the predominant read-only case. It has been verified to solve the lock congestion issue in our load tests.
The modification drastically improves the performace of the read-only case, but adds some overhead (an entry lookup) in the modifying case. This tradeoff might not be feasible for all usages of
ConcurrentReferenceHashMap. A similar issue has been identified (and improved, considering the inherent tradeoff) almost a decade ago in the JDK: https://bugs.openjdk.java.net/browse/JDK-8161372