Skip to content

Conversation

@gampleman
Copy link
Collaborator

Fixes #65.

It replaces rightOf with an implementation based on String.indexes, which seems consistently much faster (about 10x in the N=1000 case) than the existing regex approach.

Screenshot 2025-03-06 at 16 13 27

Interestingly, leftOf is faster using String.indexes with a low number of matches (for instance when tested with 10 matches), but becomes significantly slower as the number of matches increases (with a 1000 matches, it is much slower than the regex version).

Those are the results in Webkit. In Chromium the results look a bit different:

Screenshot 2025-03-06 at 16 17 46

Same thing in Spidermonkey:

Screenshot 2025-03-06 at 16 20 07

At the moment I'm thinking of replacing rightOf with the String.indexes based version, since in Webkit it's such a clear win, the performance in Chrome isn't terrible and well... basically nobody uses Firefox...

@gampleman gampleman requested review from lue-bird and miniBill March 6, 2025 14:23
@miniBill
Copy link
Collaborator

miniBill commented Mar 6, 2025

[I use Firefox 😭]
I think that realistically, you wouldn't use rightOf/leftOf in a string with 10k matches? My expectation is that the median number of matches is 1, and the average probably not much higher, so switching to the indexes-based approach makes sense to me for both

@gampleman gampleman merged commit 7c09809 into master May 19, 2025
2 checks passed
@gampleman gampleman deleted the fix-right-of branch May 19, 2025 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

String.Extra.rightOf does not return anything past line breaks.

3 participants