Closed Bug 1398226 Opened 7 years ago Closed 7 years ago

Remove the indirection through NewDependentString in StaticStrings::getUnitStringForElement

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla57
Tracking Status
firefox57 --- fixed

People

(Reporter: anba, Assigned: anba)

Details

Attachments

(1 file)

It shaves a couple of milliseconds if we remove the extra indirection through NewDependentString.
Attached patch bug1398226.patchSplinter Review
Directly calling NewInlineString avoids the second static-strings lookup in [1], and because we know that JSDependentString::new_ [2] will always create an inline string for one-element strings, we can directly call NewInlineString. We also know that result string is definitely a two-byte string, because the UNIT_STATIC_LIMIT check in [3] failed.

I've also changed str_enumerate to use StaticStrings::getUnitStringForElement(...) for consistency with str_resolve [4].

[1] http://searchfox.org/mozilla-central/rev/44c693914255638d74bcf1ec3b0bcd448dfab2fd/js/src/vm/String.cpp#1147-1157
[2] http://searchfox.org/mozilla-central/rev/44c693914255638d74bcf1ec3b0bcd448dfab2fd/js/src/vm/String-inl.h#171-184
[3] http://searchfox.org/mozilla-central/rev/44c693914255638d74bcf1ec3b0bcd448dfab2fd/js/src/vm/String-inl.h#349
[4] http://searchfox.org/mozilla-central/rev/44c693914255638d74bcf1ec3b0bcd448dfab2fd/js/src/jsstr.cpp#558
Attachment #8906030 - Flags: review?(jdemooij)
Improves this µ-benchmark from ~410-430ms to ~360-380ms for me:

    var s = "Ā".repeat(50); // Ā is U+0100 (LATIN CAPITAL LETTER A WITH MACRON)
    var q = 0;
    var t = dateNow();
    for (var i = 0; i < 100000; ++i) {
        q += s.split("").length;
    }
    print(dateNow() - t);
Comment on attachment 8906030 [details] [diff] [review]
bug1398226.patch

Review of attachment 8906030 [details] [diff] [review]:
-----------------------------------------------------------------

Nice
Attachment #8906030 - Flags: review?(jdemooij) → review+
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/cdaed5454569
Remove the indirection through NewDependentString when creating inline-strings in StaticStrings::getUnitStringForElement. r=jandem
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/cdaed5454569
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla57
You need to log in before you can comment on or make changes to this bug.