-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Performance improvements to DefaultThreadContextMap #2321
Conversation
Yes, bumping the package version to Unfortunately your This potential memory leak problem is the only reason we even keep The performance improvements in your benchmark are however very promising. Can you check the performance of your
to your JVM parameters. |
Ugh, the memory leak problem makes sense, and using a WeakReference to track the instance would potentially lose the state. :( Thank you for explaining. I'll do the perf comparison you suggest. |
Your point is valid, this is comparable to CopyOnWriteSortedArrayThreadContextMap. Closing. |
@ppkarwasz I had an idea: my map implementation was based on a single object (Object[]), which is a JVM class. If we only put the Object[] into the ThreadLocal, we'd avoid the memory leak and could create custom Maps for not-quite-free, since all they do is wrap the array. Could even turn the copy-and-modify operations into static methods and avoid allocating the map for internal operations. A similar approach could be applied to the existing SortedArrayStringMap, although the extra internal flags (immutable, iterating, keys, size, threshold, values) would need to combined into a single Array, probably with reserved slots for the flags. Thoughts? |
Great idea, it should work. @jvz, do you confirm? Can you make another implementation of In 3.x we got rid of most Remark: the |
Yeah I think that would work. |
PR #2330 adds |
This implements a performance optimization described on issue #2319 and detailed discussion of the performance characteristics is present there, including a JMH benchmark w/ results.
Note that building change causes complaints about api versioning, and I doubt I got those flags correct. I was able to build locally by updating the package info and pom to 2.24.0.