String iteration over a rope can be slow

NEW
Unassigned

Status

()

P3
normal
a year ago
a year ago

People

(Reporter: anba, Unassigned)

Tracking

({triage-deferred})

Trunk
triage-deferred
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

a year ago
Created attachment 8888276 [details] [diff] [review]
bug-rhs-ropes-loadstring.patch

It can be slow for basically the same reason as in bug 1331136: We won't flatten the rope because of the optimization in JSString::getChar(), which means we always call into the runtime to retrieve char.

Example benchmark:
    var q = 0;
    var dt = 0;
    for (var i = 0; i < 1000000; ++i) {
        var s = "a".repeat(15);
        s = s.split("").join(""); // flatten
        s = s + s; // rope

        var t = dateNow();
        for (var k of s) ++q;
        dt += dateNow() - t;
    }
    print(dt, q);

This µ-benchmark currently completes in ~525ms for me, adding support to load a char from right-hand side of a rope to MacroAssembler::loadStringChar() (see attached patch) would improve it to ~380ms. 

The question is now whether or not it's worth it to handle the rhs of a rope in MacroAssembler::loadStringChar()?
Keywords: triage-deferred
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.