Skip to content
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

Improvements in ThreadLocalStorage #553

Merged
merged 4 commits into from
Oct 13, 2018
Merged

Conversation

dpsoft
Copy link
Contributor

@dpsoft dpsoft commented Sep 12, 2018

  • Wrapper that implements optimized ThreadLocal access pattern ideal for heavily used ThreadLocals.

  • It is faster to use a mutable holder object and always perform ThreadLocal.get() and never use ThreadLocal.set(), because the value is more likely to be found in the ThreadLocalMap direct hash
    slot and avoid the slow path ThreadLocalMap.getEntryAfterMiss().

  • With a twist proposed by @adriancole where we don't use an Kamon-defined holder object as that would prevent class unloading.

JMH Results:

taskset -c 0-2 sbt 'coreBench/jmh:run -i 10 -wi 5 -t2 .*Benchmark.*'

[info] Benchmark                                       Mode  Cnt   Score   Error  Units
[info] ThreadLocalStorageBenchmark.currentThreadLocal  avgt  100  17.579 ± 0.261  ns/op
[info] ThreadLocalStorageBenchmark.fastThreadLocal     avgt  100  13.769 ± 0.275  ns/op

@dpsoft
Copy link
Contributor Author

dpsoft commented Sep 26, 2018

All credits to FastThreadLocal by @trask

@trask
Copy link

trask commented Sep 26, 2018

👍

@codefromthecrypt
Copy link
Contributor

codefromthecrypt commented Sep 26, 2018 via email

@codefromthecrypt
Copy link
Contributor

codefromthecrypt commented Sep 26, 2018 via email

Copy link
Contributor

@ivantopo ivantopo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple stupid comments, but in general looks good to me! Thanks @adriancole for the support and @trask for the original awesomeness :D

build.sbt Outdated Show resolved Hide resolved
@ivantopo ivantopo merged commit aad6a8b into master Oct 13, 2018
@dpsoft dpsoft deleted the thread-local-improvements branch October 13, 2018 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants