-
Notifications
You must be signed in to change notification settings - Fork 443
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
Avoid allocating new string when output_postamble is blank #1911
Avoid allocating new string when output_postamble is blank #1911
Conversation
f286a28
to
ccdf1c6
Compare
38077f6
to
2e58f1f
Compare
CI is failing, but I'm not sure how to address it. I'm assuming it has something to do with changes on Rails I ran a slightly modified version of the existing benchmarks (Ruby 3.2.2 on an Apple M1 Pro), and it does show a pretty good performance improvement when there is no
The benchmarks in CI show improvements as well:
|
2e58f1f
to
0ed8013
Compare
0ed8013
to
9462fc5
Compare
@mitchellhenke sorry about the late reply, I can't seem to find your issue, @joelhawksley are you able to help |
@reeganviljoen apologies, I didn't create an issue for this one, but I am happy to if it is helpful |
Thank you for the review and merge! |
What are you trying to accomplish?
This pull request is strictly to improve performance by reducing allocations
What approach did you choose and why?
The change is exclusively focused on the
output_postamble
method and the default empty string. The concatenation calls https://github.com/rails/rails/blob/v7.0.8/activesupport/lib/active_support/core_ext/string/output_safety.rb#L247-249 which includes a duplication of the original string and concatenation of an empty one.Avoiding the concatenation saves an allocation of the rendered template, which can be quite large.
This was found while working on #1884.
Anything you want to highlight for special attention from reviewers?
The code changes are quite small, but a potentially significant thing I'm not sure of is whether there is a good way to add tests.