[ad_1]
Use frozen_string_literal
:
frozen_string_literal
reduces the generated garbage by ~100MB or ~20%! Free performance by adding a one line comment.Conclusion
Gem authors: add# frozen_string_literal: true
to the top of all Ruby files in a gem. It gives a free performance improvement to all your users as long as you don’t use String mutation.
Mike Perham: Ruby Optimization with One Magic Comment, 2018-02-28: https://www.mikeperham.com/2018/02/28/ruby-optimization-with-one-magic-comment/
Use Symbol
as hash keys:
If you use Ruby 2.2,
Symbol
could be more performant thanString
asHash
keys.
Fast Ruby: https://github.com/fastruby/fast-ruby#hash
[ad_2]