Feature #12009
Updated by nobu (Nobuyoshi Nakada) over 9 years ago
~~~ With the following example, this reduces allocations from 346 to 324 strings when calling `Psych.load` Psych.load on a 26-entry hash: --------------------------------------------------------------- -------------------------------8<-------------------------------- ~~~ruby require 'psych' require 'objspace' before = {} after = {} str = [ '---', *(('a'..'z').map { |k| "#{k * 11}: 1" }), '' ].join("\n") GC.disable ObjectSpace.count_objects(before) h = Psych.load(str) ObjectSpace.count_objects(after) p(after[:T_STRING] - before[:T_STRING]) ~~~ --------------------------------------------------------------- -------------------------------8<-------------------------------- Allocating 324 strings for 26 hash keys is still expensive. More work will be needed to reduce allocations further... Tested on x86-64. It would actually be awesome if `Psych` Psych could use the `fstring` fstring table and have string keys auto-deduped as in Ruby source code. ~~~