From: Eric Wong Date: 2015-12-02T21:36:31+00:00 Subject: [ruby-core:71804] Re: [Ruby trunk - Bug #11759] URI breaks with frozen strings colin@invoca.com wrote: > Isn't it sufficient to initialize the string buffer with String.new? Yes, but I prefer to avoid String.new because the constant lookup requires an inline cache lookup + storage entry in the iseq. Here's their respective disassembly code: ''.freeze.dup == disasm: #@>================================ 0000 trace 1 ( 1) 0002 opt_str_freeze "" 0004 opt_send_without_block , 0007 leave String.new == disasm: #@>================================ 0000 trace 1 ( 1) 0002 getinlinecache 9, 0005 getconstant :String 0007 setinlinecache 0009 opt_send_without_block , 0012 leave But maybe String.new is slightly faster; but I normally prefer smaller code unless something is called in a tight loop.