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
Replace interpolated interpolation with cleaner method #965
Merged
Conversation
This file contains 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
@oniofchaos Could you squash your commits, resolve the conflict in CHANGELOG, then push -f please? |
In micro-benchmarking, this change performs within margin of error of the existing code but saves a string allocation each time the method is called (assuming the quote strings in the old code were frozen). ``` begin require "bundler/inline" rescue LoadError => e $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" raise e end gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" end def allocate_count GC.disable before = ObjectSpace.count_objects yield after = ObjectSpace.count_objects after.each { |k,v| after[k] = v - before[k] } after[:T_HASH] -= 1 # probe effect - we created the before hash. GC.enable result = after.reject { |k,v| v == 0 } GC.start result end interpolated = "hi" puts "'"' + interpolated + '"'" puts allocate_count { 1000.times { '"' + interpolated + '"' } } puts "%(\"\#{interpolated}\")" puts allocate_count { 1000.times { %("#{interpolated}") } } puts "\"\#{interpolated}\"" puts allocate_count { 1000.times { "\"#{interpolated}\"" } } Benchmark.ips do |x| x.report("'"' + interpolated + '"'") { '"' + interpolated + '"' } x.report("%(\"\#{interpolated}\")") { %("#{interpolated}") } x.report("\"\#{interpolated}\"") { "\"#{interpolated}\"" } x.compare! end ```ruby ``` ' + interpolated + ' {:FREE=>-1892, :T_STRING=>2052} %("#{interpolated}") {:FREE=>-1001, :T_STRING=>1000} "#{interpolated}" {:FREE=>-1001, :T_STRING=>1000} Warming up -------------------------------------- ' + interpolated + ' 81.706k i/100ms %("#{interpolated}") 106.128k i/100ms "#{interpolated}" 137.855k i/100ms Calculating ------------------------------------- ' + interpolated + ' 3.892M (±23.2%) i/s - 17.975M in 5.007068s %("#{interpolated}") 3.722M (±17.3%) i/s - 17.830M in 5.022549s "#{interpolated}" 3.725M (±15.0%) i/s - 18.059M in 5.023493s Comparison: ' + interpolated + ': 3892392.6 i/s "#{interpolated}": 3725385.8 i/s - same-ish: difference falls within error %("#{interpolated}"): 3722401.7 i/s - same-ish: difference falls within error ```
@amatsuda done! |
Thanks! |
netbsd-srcmastr
pushed a commit
to NetBSD/pkgsrc
that referenced
this pull request
Mar 24, 2020
Update ruby-haml to 5.1.2. pkgsrc change: add "USE_LANGUAGES= # none". ## 5.1.2 Released on August 6, 2019 ([diff](haml/haml@v5.1.1...v5.1.2)). * Fix crash in some environments such as New Relic by unfreezing string literals for ParseNode#inspect. [#1016](haml/haml#1016) (thanks [Jalyna](https://github.com/jalyna)) ## 5.1.1 Released on May 25, 2019 ([diff](haml/haml@v5.1.0...v5.1.1)). * Fix NameError bug for that happens on ruby 2.6.1-2.6.3 + haml 5.1.0 + rails 4.2.x + erubi. (Akira Matsuda) ## 5.1.0 Released on May 16, 2019 ([diff](haml/haml@v5.0.4...v5.1.0)). * Rails 6 support [#1008](haml/haml#1008) (thanks [Seb Jacobs](https://github.com/sebjacobs)) * Add `escape_filter_interpolations` option for backwards compatibility with haml 4 defaults [#984](haml/haml#984) (thanks [Will Jordan](https://github.com/wjordan)) * Fix error on empty :javascript and :css filter blocks [#986](haml/haml#986) (thanks [Will Jordan](https://github.com/wjordan)) * Respect changes in Haml::Options.defaults in `Haml::TempleEngine` options (Takashi Kokubun) * Un-freeze TempleEngine precompiled string literals [#983](haml/haml#983) (thanks [Will Jordan](https://github.com/wjordan)) * Various performance/memory improvements [#965](haml/haml#965), [#966](haml/haml#966), [#963](haml/haml#963) (thanks [Dillon Welch](https://github.com/oniofchaos)) * Enable `frozen_string_literal` magic comment for all .rb files [#967](haml/haml#967) (thanks [Dillon Welch](https://github.com/oniofchaos))
This was referenced Mar 16, 2021
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.
In micro-benchmarking, this change performs within margin of error of
the existing code but saves a string allocation each time the method is
called (assuming the quote strings in the old code were frozen).
results of
benchmark.rb
compared to current master