Project

General

Profile

Actions

Bug #9079

closed

Interpolated Symbol creates unnecessary intermediate String on the heap

Bug #9079: Interpolated Symbol creates unnecessary intermediate String on the heap

Added by wycats (Yehuda Katz) about 12 years ago. Updated over 6 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.0.0p343 (2013-10-31) [x86_64-linux]
Backport:
[ruby-core:58159]

Description

This case:

x = "world"
y = :"hello#{world}!"

allocates one T_STRING according to ObjectSpace.count_objects. Since all of the concatenation happens as part of the symbol generation, it shouldn't be necessary to create a Ruby string.

Updated by Anonymous about 12 years ago Actions #1 [ruby-core:58161]

To shed a bit of light on why this happens, it turns out :"" syntax is just sugar for "".intern:

~ trunk λ ruby --dump=insns -e ':"hello #{123}"' == disasm: <RubyVM::InstructionSequence:<main>@-e>====================== 0000 trace 1 ( 1) 0002 putobject "hello " 0004 putobject 123 0006 tostring 0007 concatstrings 2 0009 opt_send_simple <callinfo!mid:intern, argc:0, ARGS_SKIP> 0011 leave 

Updated by ko1 (Koichi Sasada) almost 12 years ago Actions #2 [ruby-core:59044]

  • Target version set to 2.6

Does it has huge impact?
It is easy to add an instruction (replace concatstrings to concatstrings_and_make_it_symbol) or add a method like that.
However, it has a bit problem about encoding.
Current implementation is easy and safe, because we can catch up encoding related change to String.
I want to remain this issue, if this does not have huge impact for performance.

Updated by ko1 (Koichi Sasada) about 10 years ago Actions #3

  • Status changed from Open to Feedback

Updated by jeremyevans0 (Jeremy Evans) over 6 years ago Actions #4

  • Status changed from Feedback to Closed
  • Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN)
Actions

Also available in: PDF Atom