-
Notifications
You must be signed in to change notification settings - Fork 450
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 #511
Conversation
Interesting! Nice improvements. Can you brainstorm ways of removing the new use of |
@Marwes Also, if you're going to continue digging into more performance optimizations outside this PR, I'd like to request that we limit their scope to smaller changes. I am planning a complete rearchitecture of this crate and don't want to push much harder on the existing infrastructure. |
In 1.21 there are The safety considerations is the same for
I have no idea how much it improves for other cases but it should always be an improvement as it avoids an allocation and copy for every created state. It wasn't the most significant improvement however and if you expect that
I am not planning on doing any further improvements. I have just been doing some experimentation from time to time and these were the changes that actually made a noticeable difference. So I just packed it all up today as something mergeable. |
I saw this while looking through some issues which is part of why I didn't want to let the branch get stale, hopefully at least some of the changes are agnostic enough to survive it. |
ping @BurntSushi Is any of these changes still interesting? Should I remove the improvement involving unsafe? |
@Marwes Thanks for pinging me on this. I think in order for me to be comfortable with the |
While that particular The cost of increasing non-atomic counter will be pretty much negligible compared to everything else regex already does, and it would still save the memory in the same way unsafe |
@RReverser I would just replace it with
|
@Marwes Hmm, why do you need either |
Maybe I am forgetting something but I don't think there is a way to construct a variable sized |
Oh I was going to say you can convert it from |
Re-ran the benchmarks on just the unsafe addition and there were only a ~1% speedup so I removed it. Using double indirection + |
Ah, that's even better news. |
Ping @BurntSushi (unsafe is removed losing only a small bit of the overall improvement) |
@Marwes Does this still give 2x (?) memory saving after the unsafe removal? |
No, |
Hmm, maybe it's worth using Rc then after all? It was kind of nice improvement... |
If the only thing stopping us from the nicer and safe solution is Rust 1.21, then I say we just go with that. I guess I can make the next release a 1.1.0 release and bump the minimum Rust version. |
Actually, |
Added back the
Even the small strings in the added benchmarks yielded an average state size of > 30 bytes so it shouldn't be worse in memory use except perhaps in degenerate cases. |
d4ad8b3
to
e585739
Compare
Is Arc as opposed to Rc really needed there? Isn't owning struct already accessed via thread-safe wrapper? If so, this would just add unnecessary overhead. |
@RReverser You still need a |
Yeah, it is a bit odd that a thread local value needs Also Amanieu/thread_local-rs#3 Failure looks spurious (network connectivity during setup). |
a3590f7
to
01241bb
Compare
@BurntSushi This ought to be good now. |
Ping @BurntSushi |
@Marwes Yes, I know I'm on the hook for this. It's going to take me some time to get around to merging it. |
☔ The latest upstream changes (presumably a3bccb1) made this pull request unmergeable. Please resolve the merge conflicts. |
Shaves of a few percent on dfa heavy regexes such as `RegexSet` use.
Avoids frequent re-allocations while the instructions are pushed to it.
Necessary for `From<&[T]> for Arc<T>`
Various improvements from profiling
RegexSet::matches
usage.