-
-
Notifications
You must be signed in to change notification settings - Fork 926
Optimizations for dynamic string building #8180
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
They will never be seen and can never be mutated by a user.
0c0d89d
to
26c16ad
Compare
This patch introduces a new indy call site for dynamic strings. Instead of using frozen strings for the constant bits and doing all construction and concatenation in the call-side bytecode, this version embeds all constant strings into the indy call site and passes the dynamic arguments only. This moves all concatenation logic into the call site, where it can be specialized for small arities or dumped into a generic large-arity string builder. Note about consecutive static strings: These probably should not happen, but due to the way we propagate literal frozen strings it's possible to have multiple static string pieces in a row. We will want to look at the optimizations done in LocalOptimizationPass to re-calcuate the condensed set of operands (combining consecutive string elements) to ensure we are not wasting cycles on concatenating multiple static strings that could be a single operation.
When the dynamic elements of a dstring are not trivially appendable, we must dynamically dispatch to to_s to get a string result back. However, we don't want to always dispatch to to_s, so this patch introduces a marker interface Appendable that indicates there is a fast path for appending certain core types. The indy call site for dstring will bind each dynamic element to a type check and branch to the to_s call if necessary, and then proceed to append each element in turn, either as its Appendable form or as its to_s result or, eventually, as an anyToString generic form. This improves performance of dynamic strings containing non- trivial dynamic elements that must be to_s'ed. This patch also introduces a second less-specialized path for up to 5 dynamic elements that avoids using an argument box. This returns such cases back to the performance of the old non-indy "pre-inlined" version of this logic and could possibly be expanded to larger arities as long as the switch does not start to be a bottleneck.
This can be expanded to cover more core types, but currently is only implemented by String, Fixnum, Float, and Symbol.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR will include various optimizations for dynamic string build and manipulation, including at least: