Closed Bug 1782959 Opened 1 year ago Closed 1 year ago

Inline String.prototype.startsWith with constant search strings

Categories

(Core :: JavaScript Engine: JIT, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
105 Branch
Tracking Status
firefox105 --- fixed

People

(Reporter: anba, Assigned: anba)

References

Details

Attachments

(5 files)

Bug 1734405 added code to perform inline string comparisons. We can reuse that code to speed-up String.prototype.startsWith when the search string is a constant string. (Constant search strings are quite common [1] when compared to non-constant search string [2].)

Real-world use case:
Scrolling down on https://www.twitch.tv/directory generates 100K calls to String.prototype.startsWith whenever new content is loaded. After this patch, only the non-Warp calls are left (10-30K calls in total).

[1] Constant search string: https://searchfox.org/mozilla-central/search?q=%5C.startsWith%5C%28%5B%22%27%5D&path=&case=true&regexp=true
[2] Non-constant search string: https://searchfox.org/mozilla-central/search?q=%5C.startsWith%5C%28%5B%5E%22%27%5D&path=&case=true&regexp=true

For now simply call into the VM. Part 3 will add an optimisation when the
search string is a constant, which is by far the most common use.

Part 3 will use this function.

Depends on D153592

This is by far the most common use and it's easy to optimise this case.

Depends on D153593

Instead of directly calling startsWith, some code uses substring to check
for string prefixes. Let's detect this pattern, so we can use the faster code
path added in part 3.

Depends on D153594

This ensures the folded MSubstr from part 4 can actually be DCE'ed.

Depends on D153595

Pushed by andre.bargull@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/e899c9759efb
Part 1: Inline String.prototype.startsWith. r=jandem
https://hg.mozilla.org/integration/autoland/rev/143b9d7369d6
Part 2: Move character comparison out of visitCompareSInline. r=jandem
https://hg.mozilla.org/integration/autoland/rev/a67e33b06bf3
Part 3: Inline String.prototype.startsWith with a constant search string. r=jandem
https://hg.mozilla.org/integration/autoland/rev/d795d3eb83e2
Part 4: Fold substring as startsWith pattern. r=jandem
https://hg.mozilla.org/integration/autoland/rev/41bc59adbe5f
Part 5: Implement recover support for MSubstr. r=jandem
You need to log in before you can comment on or make changes to this bug.