Everyone wants their programs to be faster and to take up less memory. However, it's not often that this is achieved without having to modify source code. This post will introduce optimizations added in Ruby 2.2.0 when working with a Hash and string keys. To understand the optimization, you need to know current behavior.
In Ruby 2.1 and prior, if you write something like this:
[ruby] hash["access_string"] [/ruby]
Ruby will allocate the string "access_string"
in order to look for an entry with a key by that name. Similarly, Ruby has to allocate a string every time you create a hash literal:
[ruby] hash = { "foo" => @variable } [/ruby]
Continue reading %Unraveling String Key Performance in Ruby 2.2%
by Richard Schneeman via SitePoint
No comments:
Post a Comment