-
Notifications
You must be signed in to change notification settings - Fork 231
Why aren't regular expressions cached? #2113
Comments
To some extent it is. 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:
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.
Two reasons:
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))|(?=.*\\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))|(?=.*\\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))|(?=.*\\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))|(?=.*\\W)(?=.*[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.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);
}
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. |
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. |
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. |
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 sizem
(assuming JavaScript's regex engine is limited to NFA/DFA).Also, why are we doing this
try-catch
Would be better to do the validation in the UI instead.
The text was updated successfully, but these errors were encountered: