From: Eric Wong <normalperson@...>
Date: 2021-10-22T09:29:37+00:00
Subject: [ruby-core:105749] Re: [Ruby master Feature#13715] [PATCH] avoid garbage from Symbol#to_s in interpolation

"jeremyevans0 (Jeremy Evans)" <noreply@ruby-lang.org> wrote:
> @normalperson's patch: https://github.com/ruby/ruby/pull/5002,
> expanding the optimization to include nil/true/false/0-9.
> This is an across-the-board performance improvement, mostly by
> reducing the number of VM instructions from 6 to 1. From the
> benchmarks included in the patch, performance increase from
> the patch is roughly:

Thanks for bringing this up, again.  In Init_Numeric, you have:

	rb_str_freeze(rb_str_new_cstr(...));

Why not rb_fstring_cstr?

My original had a regression at loop_whileloop2, does that still
happen?  I didn't get the 6->1 instruction reduction in the
original, though, so the reduction bytecode alone seems worth it
in your version.

> It's definitely adds complexity, and I'm not sure how much of
> a difference it makes in a production application.  However,
> string interpolation is fairly common in most Ruby
> applications and libraries, and many interpolations will use
> symbols/nil/true/false/0-9, so I think it is worthy of
> consideration.

Agreed on all points.  I figured this would get lost in the
noise of typical real-world code that's overwhelmed by other
sources of garbage, so I didn't pursue it further.

However, the reduction in bytecode size nowadays seems like an
obvious win this time around.

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>