-
Notifications
You must be signed in to change notification settings - Fork 43
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
refactor: Optimize Hexadecimal Serialization and Deserialization for u64 #21
base: main
Are you sure you want to change the base?
Conversation
Multiple things, don't remove the useful documentation, sure it makes the code less complex but without a benchmark it's hard to say optimize |
I am not sure how this modification makes the serialization routines faster. They are doing the same exact thing, except without using iterators. In the deserialization function, you add a If you really need to optimize those functions, I think the best is to junp down to unsafe code and access the string without checking bounds within the loops, and avoid checking whether the final string is valid UTF-8 (we know it is because we wrote ascii characters to it). That being said, is that gain really worth introducing unsafe code into the codebase? |
The bounds checks are likely optimized out if you check the length beforehand. What may be more interesting here is replacing In any case, without a benchmark this is all a bit moot. I'm in favor of it if it simplifies the code, not so much if we claim it's faster, make it more complex, and provide no evidence of speed improvement. |
Also, if we have no benchmark I would much rather just use |
Ahah, now that I think about it, using stdlib might even be faster than what I had wrote 😅 |
Pull Request type
What is the current behavior?
Before these changes, the
serialize
anddeserialize
methods foru64
in theNumAsHex
trait were implemented with less emphasis on performance optimization. The serialize method utilized a dynamic approach for string construction, and deserialize handled hexadecimal string parsing without specific optimization techniques. While fully functional, these implementations had potential areas for performance improvement, especially in scenarios involving large-scale or frequent serialization/deserialization operations.Resolves: #NA
What is the new behavior?
serialize
method in theNumAsHex
trait foru64
to use a fixed-size buffer, enhancing performance and reducing memory overhead.deserialize
method for improved efficiency in parsing hexadecimal strings intou64
, using a more direct approach and safe overflow handling withchecked_mul
andchecked_add
.Does this introduce a breaking change?
No
Other information
This PR focuses on enhancing performance without altering the functionality of the existing code. It has been thoroughly tested to ensure that the new implementations of
serialize
anddeserialize
maintain the same behavior as their predecessors.