Eric Wong <normalperson / yhbt.net> wrote:
> Maybe start moving existing iseq_compile_each optimizations to the
> peephole optimizer (work-in-progress):
> http://80x24.org/spew/m/ee49aae645e0953fc16fc1557dce6a09b4de4324.txt

Part #2, generic putstring_for instruction:
http://80x24.org/spew/m/5a77be4e211c81a509573e3e1ca3bc3ca2383e68.txt

A new putstring_for instruction may replace all current uses of:

* opt_str_freeze
* opt_aref_with
* opt_aset_with

This new instruction should also be usable to implement new
optimizations to avoid rb_str_resurrect.

Optimizations for literal hash["literal"] (aref/lookup) and
"literal".freeze are easily moved to the peephole optimizer.

However, it seems easier to optimize `hash["literal"] = val'
in iseq_compile_each right now.

This reduces performance compared to the old opt_aref_with and
opt_aset_with instructions slightly, but is more elegant for in
avoiding special cases.  We may decide to resurrect opt_aref_with
and opt_aset_with if we want to recover the small performance loss
and can accept a bigger VM loop.

"".freeze performance is probably not interesting to anyone :)

benchmark results:
minimum results in each 5 measurements.
Execution time (sec)
name                    2.1.3   trunk   built
loop_whileloop2         0.106   0.106   0.106
vm2_hash_aref_lit*      0.503   0.162   0.192
vm2_hash_aset_lit*      0.587   0.214   0.241

Speedup ratio: compare with the result of `2.1.3' (greater is better)
name                    trunk   built
loop_whileloop2         1.000   0.998
vm2_hash_aref_lit*      3.099   2.621
vm2_hash_aset_lit*      2.741   2.435