Remove the indirection through NewDependentString in StaticStrings::getUnitStringForElement

RESOLVED FIXED in Firefox 57

Status

()

enhancement
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: anba, Assigned: anba)

Tracking

Trunk
mozilla57
Points:
---

Firefox Tracking Flags

(firefox57 fixed)

Details

Attachments

(1 attachment)

(Assignee)

Description

2 years ago
It shaves a couple of milliseconds if we remove the extra indirection through NewDependentString.
(Assignee)

Comment 1

2 years ago
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)
(Assignee)

Comment 2

2 years ago
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+

Comment 5

2 years ago
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
Last Resolved: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla57
You need to log in before you can comment on or make changes to this bug.