-
Notifications
You must be signed in to change notification settings - Fork 185
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
Improve Ruby string interning #3216
Improve Ruby string interning #3216
Conversation
Previously, we always extracted the precise range of bytes we needed when looking up an entry in the frozen string table. If an entry already existed, we'd discard that extracted range in favor of what was already in the cache. This change defers making a copy of the string's bytes until we need to insert into the cache. For situations with many cache hits this approach can be much faster.
…ble. By restructuring to work with `InternalByteArray`, we can now support working with native strings as well. The `InternalByteArray` will make a copy of the native memory into a Java `byte[]`, which won't change behind our backs.
… cache key to save memory.
44ed828
to
3f4f5c4
Compare
/** Supports the creation of a cache key using a subset of bytes. This key *must* be used for lookups only. If you | ||
* want to insert into the cache, you *must* use the result of {@link #makeCacheable(boolean)}. |
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.
This is super helpful to understand this code/class, thanks!
if (bytes == null) { | ||
return 0; | ||
} |
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.
bytes
can never be null, right? I'll just remove this then.
(it probably comes from Arrays#hashCode checking that)
This is essentially the follow-up work to #3185. I didn't realize that rebasing my branch and pushing that up was going to break the branch link in GitHub. Since it did, I can't re-open that PR. I'm sorry for the churn.