-
Notifications
You must be signed in to change notification settings - Fork 6
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
rust: amortize allocations #2
base: master
Are you sure you want to change the base?
rust: amortize allocations #2
Conversation
This is a PoC for only the Rust code that shows how to optimize it a bit more by both amortizing allocation and reusing the result of UTF-8 decoding instead of repeating it for each iteration of the inner loop. The results on my machine: $ yarn bench yarn run v1.22.4 $ node run.js bench go: 1.573124 javascript: 2.94 rust: 1.295147587 Done in 6.17s. Of course, this isn't a fair comparison, since this doesn't update the Go code to reuse allocation either. Although it wouldn't be surprising if its GC was doing this automatically anyway. I'm not necessarily submitting this with a request to merge it, but rather, just providing more data.
I'm on a MacBook Pro 2017, and I applied #3 because it fixes and improves the Golang version.
go: 1.688000
javascript: 3.84
rust: 1.876212421
go: 1.685848
javascript: 3.845
rust: 1.655761329 MacOS's allocator could still be partly to blame. |
Thanks for making the comparisons @mlbright. Even with #3 it's still not fair to compare this version to the go implementation unfortunately. You would need to amortize the slice allocations like @BurntSushi has done here – I imagine placing them on a struct like he has done would work. |
That's true, but if we just focus on Rust for a moment, I think the memory allocator on the Mac makes a big difference. I have a similar language comparison for a less useful algorithm. Ignore that my data structures are not ideal and that the comparison is again not fair. The performance difference as a result of changing allocators is dramatic.
|
This is a PoC for only the Rust code that shows how to optimize it a bit
more by both amortizing allocation and reusing the result of UTF-8
decoding instead of repeating it for each iteration of the inner loop.
The results on my machine:
Of course, this isn't a fair comparison, since this doesn't update the
Go code to reuse allocation either. Although it wouldn't be surprising
if its GC was doing this automatically anyway.
I'm not necessarily submitting this with a request to merge it, but
rather, just providing more data.