-
Notifications
You must be signed in to change notification settings - Fork 17
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
Slow performance in a loop #13
Comments
So all regexes are already compiled during initialization, so that's not the cause. The cause is likely unicode support in Rust, which makes regex much more complicated. My fork/PR here #14 disables unicode support and provides a significant speedup as well as some memory savings. You can see an example of how to set up the parser without unicode support here: https://github.com/davidarmstronglewis/uap-rs/pull/14/files#diff-27d11095d02b2115142e677214a2e2791f4a6158c7e12c367338dfa8378ceed7 I'd love to see your comparison with this new code. The benchmark suite has a 3x+ speedup for the user_agent parsers, so hopefully that makes rust beat c# in your example. |
With #14 now merged (thank you @hamiltop) and version 0.6.1 released I would be curious where performance lands compared to your C# example. Feel free to share your findings and if you're satisfied close this issue, @closte. I can also imagine a silly optimization of memoizing user agent strings to avoid re-running the regex; but I'm not sure how much of a difference in performance and may not be worth the optimization. |
I made a simple test and the same 1000 iterations ends is just +-30ms, faster than C# and way, way faster than the previous code. Thanks |
Seriously, great work @hamiltop 🙌 |
A few days ago I was testing the .NET C# integration of the UA Parser and I`m getting way faster execution time compared to your solution and Rust language.
Rust language is well known to be faster than C# in almost all cases.
Iterations: 1000
Rust (cargo run --release:): ~280ms for 1000 iterations
C#: ~130ms for 1000 iterations
Rust code looks like this:
C# code looks like this:
I`m very newbie to Rust but maybe you can make all regex compiled/static like on the following URL or why the Rust implementation is almost double slower?
The text was updated successfully, but these errors were encountered: