perf(compression): use regex exec instead of match#210
perf(compression): use regex exec instead of match#210lukeed merged 1 commit intolukeed:nextfrom bluwy:use-regex-exec
Conversation
|
might make sense to hoist the regexps too? |
|
The perf improvement from hoisting regex varies quite a bit in my experience and often doesn't yield noticable returns. I think engines are able to optimize them well enough these days. Maybe those with |
|
released as |
|
@bluwy Last time we benched it for valibot, it was ~2ms faster to hoist (even non global regexps) |
|
Yeah it'll depend but it's often a very small amount that I've come to prefer not bugging libraries to hoist them unless really needed 😅 |
|
It generally has a significant impact in repeat synchronous usage (eg loops), so seeing it in valibot makes sense. In an async-like callback (like here) it won’t matter much, especially with simple patterns |
I was running
eslint-plugin-regexpin polka and found we can refactor thestr.match(re)tore.exec(str)for perf.I made some tests and can confirm there's a sizable perf improvement with exec. (perf.link test)