Reduce synchronization lock contention in common code paths #41816
+45
−9
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.
Description
Prototype PR aiming to reduce synchronization and lock contention in common code paths.
new URL(String)
requires a lookup to get theURLStreamHandler
for theURL
. This lookup uses aHashTable
which hassynchronized
applied to its APIs. In highly threaded environments this can result in drastic contention. There is a similar APInew URL(URL, String)
which takes an existingURL
and copies information from that to the newURL
being parsed. If the existingURL
already has aURLStreamHandler
it circumvents the lookup. Prototype here is using a simpleURL
that only contains values that will be overridden by the newURL
(host).Collator.getInstance(Locale.ROOT)
can result in aCollator
instance thatsynchronized
itscompare
method. This PR modifies the usage to be aThreadLocal
so there isn't contention when using the instance as it'll be local to the callingThread
. Additional investigation should be done ifString.compareTo
andString.CASE_INSENSITIVE_ORDER
could be used instead of aThreadLocal
as those don'tsynchronized
and don't requireThread
-based variables.All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines