Conversation
be477e6 to
c5f5d3e
Compare
|
@tagliala, thanks for the PR and the explanation! I've double checked and, indeed, the only method that could be affected is I wonder if we should prevent unexpected consequences (eg. we want to use Something like |
88dde2e to
bd82c87
Compare
|
@tjschuck can you triple-check this one?! I am also inclined to remove the Code Climate check since Code Climate is going to be replaced anyways! what do you think?! |
|
Much better, thanks. I've rebased but now codeclimate complains. I would not split this method and passing the parameters around again. Let me know how do you want to proceed |
The only method that may potentially be affected is `Money::Formatter#append_currency_symbol`. This method has been refactored to avoid any potential side effect with string mutations Additionally, a `Lint/RedundantStringCoercion` offense has been fixed Close RubyMoney#1108
bd82c87 to
18d46a9
Compare
|
The Anyway, I benchmarked First, the benchmark script, using # Run twice -- first do
# $ ruby bench.rb
# then do
# $ WITH_FROZEN_COMMENT=true ruby bench.rb
require 'bundler/inline'
if ENV['WITH_FROZEN_COMMENT'] == 'true'
gemfile do
source "https://rubygems.org"
gem "benchmark-ips"
gem "benchmark-memory"
gem "money", git: 'https://github.com/tagliala/money', branch: 'feature/frozen-string-literals'
end
else
gemfile do
source "https://rubygems.org"
gem "benchmark-ips"
gem "benchmark-memory"
gem "money", git: 'https://github.com/RubyMoney/money', branch: 'main'
end
end
require 'benchmark/ips'
require 'benchmark/memory'
I18n.config.available_locales = :en
Money.locale_backend = :i18n
Money.rounding_mode = BigDecimal::ROUND_HALF_UP
m = Money.from_cents(123, "GBP")
Benchmark.ips do |x|
x.report('with frozen string comment') do
m.format
end
x.report('without frozen string comment') do
m.format
end
x.hold! 'temp_results_ips'
x.compare!
end
Benchmark.memory do |x|
x.report('with frozen string comment') do
m.format
end
x.report('without frozen string comment') do
m.format
end
x.hold! 'temp_results_mem'
x.compare!
endI ran the above on all supported Rubies (3.1 – 3.4), plus 3.5.0-preview1 for good measure. 3.13.23.33.43.5.0-preview1So... sure, go for it! |
|
And yeah, let's rip out Code Climate next. Fine to ignore the ❌ from it here. |
|
Thanks @tagliala! |
The magic comment is still necessary because, as of now, no supported Ruby versions have frozen string literals enabled by default for all files. Freezing string literals by default was originally planned for Ruby 3.0, but that change was postponed and has not happened yet. It may become the default in Ruby 4.0, but until then, the comment is needed It is being discussed here: https://bugs.ruby-lang.org/issues/20205 Additional details: Probably I did run last year to check that it weren't issues (at least covered by specs) before adding the magic comment, but I forgot to mention this Ref: https://gist.github.com/fxn/bf4eed2505c76f4fca03ab48c43adc72 |
The only method that may potentially be affected is
Money::Formatter#append_currency_symbol.This method has been refactored to avoid any potential side effect
with string mutations
Additionally, a
Lint/RedundantStringCoercionoffense has been fixedClose #1108