Project

General

Profile

Actions

Feature #10326

closed

[PATCH] optimize: recv << "literal string"

Added by normalperson (Eric Wong) over 9 years ago. Updated over 9 years ago.

Status:
Rejected
Assignee:
-
Target version:
[ruby-core:65413]

Description

Concatenating literal strings to existing strings seems fairly common
practice, so avoid extra garbage when doing it. I don't know if escape
analysis is coming to Ruby, but this seems easier-to-do for now:

vm2_strcat

i = 0
str = ""
while i<6_000_000 # benchmark loop 2
  i += 1
  str << "const"
  str.clear
end
trunk	1.020890216
trunk	1.018797116
trunk	0.992393447
built	0.626914306
built	0.627910138
built	0.644469095

benchmark results:
minimum results in each 3 measurements.
Execution time (sec)

name |trunk |built
--------+-------+------
loop_whileloop2 |0.160 |0.159
vm2_strcat* |0.833 |0.468

Speedup ratio: compare with the result of `trunk' (greater is better)

name |built
--------+-------
loop_whileloop2 |1.006
vm2_strcat* |1.779

Future optimizations:

  • recv << "interpolated #{dstr}"
    (immediate free + force recycle)

  • elide allocation for equality comparisons:
    str == "literal" and "literal" == str

  • optimize << recv is IO << (str|dstr) (maybe)


Files

0001-optimize-recv-literal-string.patch (3.28 KB) 0001-optimize-recv-literal-string.patch normalperson (Eric Wong), 10/05/2014 09:29 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #10329: [PATCH 2/1] optimize: foo == "literal string"Rejected10/06/2014Actions

Updated by normalperson (Eric Wong) over 9 years ago

  • Related to Feature #10329: [PATCH 2/1] optimize: foo == "literal string" added

Updated by normalperson (Eric Wong) over 9 years ago

wrote:

Future optimizations:

  • recv << "interpolated #{dstr}"
    (immediate free + force recycle)

Tried, not worth it from what I can tell:
http://80x24.org/spew/m/7c7dd29f45920fb8fc9d2c72858334c60e0a9c58.txt
(however, a good learning experience for me)

  • elide allocation for equality comparisons:
    str == "literal" and "literal" == str

See [Feature #10329] and [Feature #10333]

  • optimize << recv is IO << (str|dstr) (maybe)

I doubt it's worth the effort because of syscall overhead. This
(#10326) is fairly minor compared to the "==" optimizations in #10329
and #10333

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Description updated (diff)

Updated by normalperson (Eric Wong) over 9 years ago

  • Status changed from Open to Rejected

obsoleted by Feature #10423

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0