-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add support for 128-bit integers #10
Conversation
Wow I did not expect u128 to be 100 times slower than u64. I would prefer not to merge this then. The advantage of this crate over std::fmt is that it avoids a small constant amount of overhead from the Formatter machinery. Going from 42ns to 10ns to print an i16 is a big deal, but going from 2530ns to 2500ns won't matter. what do you think? |
I agree there no point in adding this if it’s this slow, but I want to do some profiling before closing this. At first glace, I believe the hotspots are |
Division with remainder on u128 is badly optimized by LLVM. Copying it into our crate allows for inlining and proper optimization.
I have done some profiling and optimization. The reason it’s so slow are the We can optimize this my manually linking to Here is benchmark showing the effects of these optimizations:
At this point I think implementing the latter option makes sense, it’s over 100% faster then |
Nicely done! I filed rust-lang/rust#44583 to provide your faster implementation in std::fmt if possible. But that gets us back to the previous square -- once std has this implementation, itoa cannot really be any faster. We could provide the fast implementation in itoa until it reaches the stable compiler, then remove it. But maybe a better option would be to provide this in its own crate for now (in addition to a compiler PR). |
I don't think inlining is going to happen in std, but once rust-lang/rust/#44545 is fixed |
Adds support for 128-bit integers on the nightly compiler feature gated behind an
i128
feature flag.I used the same implementation as used by the other types, but ended up being as slow as
std::fmt
on my system. I look into why later, when I have some time.Resolves #9