-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: improve dfa matching (with tweaks) #540
Conversation
Shaves of a few percent on dfa heavy regexes such as `RegexSet` use.
Avoids frequent re-allocations while the instructions are pushed to it.
This was motivated in part for using `From<&[T]> for Arc<T>`, which technically only requires 1.21.0. However, lazy_static 1.2, which is a dependency of regex, now requires 1.24.1, so we might as well ride the wave.
rustfmt is not something I'm willing to adopt at this time, but contributors are still trying to use it anyway. This is irksome, so we attempt to prevent this from happening by creating a config that explicitly disables rustfmt.
Sorry about that, I try and disable rustfmt most of the time but I think in this case it got re-formatted during when fixing conflicts in a rebase :/
That part was ugly but it is a shame it got removed, it was actually a pretty good speedup since it avoids an allocation + copy in the common case where the cache is hit (somewhere between 5-10% if I remember). |
Yeah, I figured about the optimization. It just introduced too much complexity in code that is already way too complex. I've been trying to think about ways to rewrite the DFA so that it is simpler, and in particular handles look around in a more obvious way, but I don't have any great ideas yet. With that said, another way of looking at this is that if these types of optimizations are helping, then the DFA is spending a lot of time either building itself or thrashing, which is probably never going to be that fast in the first place. So there might be better higher level optimizations available to you. But I'm not sure. |
This PR is a riff on @Marwes' excellent work in #511. For the most part, this only contains tweaks in order to get it into a mergeable PR:
lazy_static
is now also at 1.24.1, and is a transitive dependency of regex (viathread_local
).Arc
s.And I think that's it! The rest looked great! Thanks @Marwes!
Closes #511