Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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 10 commits into from
Apr 3, 2024
Merged

Conversation

headius
Copy link
Member

@headius headius commented Apr 1, 2024

This PR will include various optimizations for dynamic string build and manipulation, including at least:

  • Bytecode size reductions
  • Specialized call site logic for string templating
  • Optimized to_s invocation for non-string dynamic elements

@headius headius added this to the JRuby 10.0.0.0 milestone Apr 1, 2024
@headius headius force-pushed the dstring_optz branch 2 times, most recently from 0c0d89d to 26c16ad Compare April 1, 2024 08:32
headius added 3 commits April 1, 2024 03:56
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.
@headius headius mentioned this pull request Apr 2, 2024
22 tasks
headius added 4 commits April 1, 2024 21:35
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.
@headius headius merged commit f231a44 into jruby:9.5-dev Apr 3, 2024
39 of 60 checks passed
@headius headius deleted the dstring_optz branch April 3, 2024 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant