-
Notifications
You must be signed in to change notification settings - Fork 9
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
Use *mut u8
to write FromHex
bytes
#123
base: master
Are you sure you want to change the base?
Conversation
2510a09
to
9e584e1
Compare
@RCasatta I try to address partially the issue you raised here, let me know what you think. I am aware this is a lot of unsafe code that you might not be comfortable with. Happy to take a less aggressive approach. |
9e584e1
to
8d5cb40
Compare
8d5cb40
to
ea2f974
Compare
Any chance you could explain why this is faster, IIUC you are replacing a call to |
Thank you for your question. As far as I understand: For a So while the collect call does allocate the total memory used in a single call, the hot loop that writes each element keeps checking that the vector has enough capacity to fit one more element: Further below, you can see the implementation for The hot loop also bumps the length on each element write. See below: |
Does a At the moment, if we return an My guess is |
Thanks @tankyleo, the performance achievement looks great! In particular in #115 most of the time is spent in decoding hex txids, thus it would gain the 2x speedup of fixed size array, Also unsafe code looks ok to me, I really would like this. That said, I am no expert in unsafe code, and given the name I think reasons explained in @tankyleo commente here should be added in code comments. I would like benches in https://github.com/tankyleo/hex-benchmarks to be added in this crate one day (as a sub-crate) |
Thanks, your function call chain looks correct. Its a bit sad that |
Could maybe add a comment to save the next guy wondering why we implement Use your own words, but if you want you could use
|
ea2f974
to
34185a0
Compare
Rebase: add a comment explaining why we implement collect manually. |
<[u8; LEN]>::from_hex
now runs in 2x fewer "Estimated Cycles" on [email protected].<Vec<u8>>::from_hex
now runs in 30% fewer "Estimated Cycles" on [email protected].Please see https://github.com/tankyleo/hex-benchmarks for benchmark code.
Partially addresses #115