Prefer inline representation over static #278
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.