-
Notifications
You must be signed in to change notification settings - Fork 77
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
Prefer inline representation over static #278
Conversation
6dc4cd1
to
0ceca1f
Compare
Would anyone have time to review this please? I believe this represents a significant performance boost for some common use cases, with no apparent downside. |
f534a9b
to
9db0317
Compare
Have rebased on top of #277 which is now based on latest main. Also made changes to improve code style (as mentioned above, I was very new to Rust when I made this PR last year so, while I believe code was correct, it wasn't very idiomatic). |
b84bfc0
to
c6ac6ab
Compare
c6ac6ab
to
538f87d
Compare
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 looks reasonable! Apologies for the long delay, and thanks for the clear motivation for the change!
No worries. Really glad to see this merged! |
As mentioned in #276, current behavior is that short strings can be stored as static strings or inline. This adds an overhead for interning short strings, as they need to be hashed and compared to possible matches in the static set.
This PR changes the behavior to always store strings of 7 bytes or less inline.
This greatly improves the performance of interning short strings - approx 250% speedup, depending on length of the string.
The benchmarks in this repo show no apparent negative effect on any other operations (though there's a lot of noise in the benchmarks).
This PR does not involve any breaking changes.
Even though interning short static atoms is very fast anyway, I imagine this change will translate to a significant real-world performance improvement for some use cases. For example, SWC uses string-cache when parsing Javascript which typically includes a lot of short variable names and tokens, especially in minified code e.g.
for (let i = 0; i < len; i++)
.Notes on implementation
StaticAtomSet::empty_string_index
would need to be removed otherwise).pack_inline()
calls in place ofpack_static()
to generate inline atoms at compile time.