Closed arextar closed 12 years ago
After testing I've found the difference may be negligible. I'll keep investigation
It my own benchmarks it seems that taking the time to access a (possibly mutable) variable in another scope is actually slower. It would make sense that an engine could optimize a regex out when it's not tied to a variable - it can treat it as though it's not mutable, as if it were a constant, and it skips the step of accessing a variable in another scope.
Although I'm not sure that's how it works, and I'm definitely not sure that's how it works in every engine, it would make sense to do it that way. But as you said, the benchmarks seem fairly close. In my experience, when a regex is not tied to a variable, it tends to be faster at least in v8. Even IE doesn't seem to have much of a problem with it.
Yeah, great work on this engine though, I always thought Sizzle could be beaten and this has definitely pulled it off.
Thanks. Unfortunately, I don't know if it will ever be used much use because it's kind of annoying to put another selector engine in jquery, or any other dom library out there. Thank you for your interest though.
One thing that I think could help speed up zest is to assign regular expressions used as variables within the closure, and then reference them where they're needed.
Example (L55)
A variable (such as r_nth) can be declared at the top of the closure (where document and window are defined)
...and then be used as such:
The following jsperf shows that it's a little faster to use this method (and every little bit helps) http://jsperf.com/regexp-creation