Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Why aren't regular expressions cached? #2113

Closed
kuroahna opened this issue Apr 9, 2022 · 3 comments
Closed

Why aren't regular expressions cached? #2113

kuroahna opened this issue Apr 9, 2022 · 3 comments

Comments

@kuroahna
Copy link

kuroahna commented Apr 9, 2022

Description
I'm reading the Yomichan source code and surprised to see that we're recompiling the regular expressions every time you do a term look up.

Why aren't we caching them? Compiling regex is really expensive and takes O(2^m) time and memory for a regular expression of size m (assuming JavaScript's regex engine is limited to NFA/DFA).

Also, why are we doing this try-catch

                try {
                    pattern = new RegExp(pattern, ignoreCase ? 'gi' : 'g');
                } catch (e) {
                    // Invalid pattern
                    continue;
                }

Would be better to do the validation in the UI instead.

@toasted-nutbread
Copy link
Collaborator

Would be better to do the validation in the UI instead.

To some extent it is.

image

However, even if Yomichan updates so that the setting value is not updated if it is invalid, there is still the potential situation where the settings could contain an invalid regex string:

  1. If we implement a validation check in the UI in a future version, users upgrading might still have erroneous regex from a previous version. I suppose this could be handled by a settings update.
  2. Importing a settings backup file with invalid regex.
  3. Advanced user tinkering could still break things, e.g. manually editing the stored settings data.

There have been situations in the past where the extension entirely stopped working due to improperly handled settings values. So to try to avoid running into that in the future, the settings values are largely treated as a user input.

The overhead of doing a try-catch is also negligible.


Why aren't we caching them?

Two reasons:

  1. The feature, at least at its introduction, has been sufficiently niche that the added performance overhead wasn't a big issue.
  2. I'm pretty sure browser Javascript engines will cache the regex. Consider the following test, based on this:
const pattern = "^(?:(?=.*[a-z])(?:(?=.*[A-Z])(?=.*[\\d\\W])|(?=.*\\W)(?=.*\\d))|(?=.*\\W)(?=.*[A-Z])(?=.*\\d)).{8,}(?:(?=.*[a-z])(?:(?=.*[A-Z])(?=.*[\\d\\W])|(?=.*\\W)(?=.*\\d))|(?=.*\\W)(?=.*[A-Z])(?=.*\\d)).{8,}(?:(?=.*[a-z])(?:(?=.*[A-Z])(?=.*[\\d\\W])|(?=.*\\W)(?=.*\\d))|(?=.*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*[A-Z])(?=.*[@#$%^&+=]).*$)?(^(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$)?(^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).*$)?(^(?=.*\\d)(?=.*[a-z])(?=.*[@#$%^&+=]).*$)?(^(?=.*\\d)(?=.*[A-Z])(?=.*[@#$%^&+=]).*$)?(^(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$)?(^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).*$)?(^(?=.*\\d)(?=.*[a-z])(?=.*[@#$%^&+=]).*$)?(^(?=.*\\d)(?=.*[A-Z])(?=.*[@#$%^&+=]).*$)?(^(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$)?(^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).*$)?(^(?=.*\\d)(?=.*[a-z])(?=.*[@#$%^&+=]).*$)?(^(?=.*\\d)(?=.*[A-Z])(?=.*[@#$%^&+=]).*$)?(^(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$)?$";

function test(str) {
  const i = Math.floor(pattern.length / 2);
  const re = new RegExp(pattern.substring(0, i) + pattern.substring(i), '');
  return str.match(re);
}

for (let i = 0; i < 10; ++i) {
  const id = `${i}`;
  console.time(id);
  test(`Foo${i}`);
  console.timeEnd(id);
}
# Chrome (NodeJS is largely the same)
0: 34.921142578125 ms
1: 17.1689453125 ms
2: 0.049072265625 ms
3: 0.0322265625 ms
4: 0.054931640625 ms
5: 0.0478515625 ms
6: 0.054931640625 ms
7: 0.0439453125 ms
8: 0.051025390625 ms
9: 0.050048828125 ms

# Firefox
0: 26ms - timer ended
1: 0ms - timer ended
2: 0ms - timer ended
3: 0ms - timer ended
4: 1ms - timer ended
5: 0ms - timer ended
6: 0ms - timer ended
7: 0ms - timer ended
8: 0ms - timer ended
9: 1ms - timer ended

So I'm not opposed to having a cache, but from some brief testing, it seems like there might not be a benefit in practice. Happy to be proven wrong though.

@kuroahna
Copy link
Author

Interesting, TIL. Java doesn't automatically cache regular expressions so I assumed JavaScript also did the same. Guess JavaScript tries to do some extra optimizations where it can.

Closing the issue, thanks again.

@toasted-nutbread
Copy link
Collaborator

Yeah, JavaScript has a lot of internal optimizations built in to things like regex, string, and array handling. Most JS engines basically seem to (rightfully) assume that most devs will write code without consideration of efficiency, so they include a bunch of optimizations like the regex caching.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants