Closed Bug 1782959 Opened 1 year ago Closed 1 year ago

Inline String.prototype.startsWith with constant search strings


(Core :: JavaScript Engine: JIT, enhancement)




105 Branch
Tracking Status
firefox105 --- fixed


(Reporter: anba, Assigned: anba)




(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 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:
[2] Non-constant search string:

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
Part 1: Inline String.prototype.startsWith. r=jandem
Part 2: Move character comparison out of visitCompareSInline. r=jandem
Part 3: Inline String.prototype.startsWith with a constant search string. r=jandem
Part 4: Fold substring as startsWith pattern. r=jandem
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.