Closed bluwy closed 2 months ago
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 g
flags could still be useful to hoist as they're more stateful.
released as @polka/compression@1.0.0-next.26
, ty @bluwy
@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-regexp
in 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)