Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes rightOf/leftOf misbehaving with newlines #75

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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 miniBill and lue-bird 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

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.
2 participants