-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
concurrent-api: shave some allocations from new Scope #3185
concurrent-api: shave some allocations from new Scope #3185
Conversation
Motivation: In the allocation profile we see anonymous instances of the new Scope being created. While not a big deal, we can do better. Modifications: We can shave these off of the default implementation by making CopyOnWriteContextMap, and really any context map, an instance of Scope. The close() method just needs to then ask the current provider to set the context to itself. Result: Less allocations.
servicetalk-concurrent-api/src/main/java/io/servicetalk/concurrent/api/ScopeContextMap.java
Outdated
Show resolved
Hide resolved
* Set the current {@link ContextMap} | ||
* @param contextMap the {@link ContextMap} to set in the thread local state. | ||
*/ | ||
void setContextMap(ContextMap contextMap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it looks more like ContextMapHolder
, should we just make this interface extend the holder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did do it, but it's a bit itchy due to the @Nullable
annotations and the return type of .context(ContextMap)
.
...-concurrent-api/src/main/java/io/servicetalk/concurrent/api/DefaultAsyncContextProvider.java
Show resolved
Hide resolved
...icetalk-concurrent-api/src/main/java/io/servicetalk/concurrent/api/AsyncContextProvider.java
Outdated
Show resolved
Hide resolved
...icetalk-concurrent-api/src/main/java/io/servicetalk/concurrent/api/AsyncContextProvider.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvement!
I'm going to merge it as-is, my optional comments may become part of your other PR if you like them:
Motivation:
In the allocation profile we see anonymous instances of the new Scope being created. While not a big deal, we can do better.
Modifications:
We can shave these off of the default implementation by making CopyOnWriteContextMap, and really any context map, an instance of Scope. The close() method just needs to then ask the current provider to set the context to itself.
Result:
Less allocations.