-
Notifications
You must be signed in to change notification settings - Fork 649
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
Improve price comparison performance #1094
Comments
I haven't looked at the internal representation of 128 bit integers, but here is an idea using assembler: If we're just checking for equality, could we just split them into 2 sets of 64 bit registers, OR them together, and see if the same value comes out that went in? You would have to do it once for each group, although you could skip the 2nd group if the first is not equal. That would be a fun exercise to benchmark. Could also try 4 byte chunks, which may be faster for ORing. Another note: While the whole post is good, see the last comment here: https://stackoverflow.com/questions/741301/how-can-i-add-and-subtract-128-bit-integers-in-c-or-c-if-my-compiler-does-not |
@jmjatlanta |
Maybe we can use __int128 to improve performance over GCC and Clang. |
Just a note here: @btsabc mentioned in #998 (comment) that MSVC doesn't support |
After done some testing, it turns out that normalization will slightly reduce performance. That means the approach mentioned in OP is a no go. There are some minor optimizations can be done about price comparison itself. I'll create a PR for them. Since 128 bit multiplication is expensive, in order to improve overall performance, we need to try to do fewer price comparison calls in the code. |
Minor optimization about price comparison #1094
Merged #1124. Closing. |
According to replay profiling data,
price::operator<()
andprice::operator>()
are in top 10.When comparing 2
price
objects, we use two 128-bit multiplications. If the amounts are smaller, will the multiplications be faster?Default
boost::rational
number is Irreducible Fraction. Butprice
is not. What if we automatically changeprice
toIrreducible Fraction
(normalize the rational number) as well?At least, if the 2 amounts are always coprime, we no longer need to use multiplication for
==
nor!=
operator.Thoughts?
This is a sub-task of #982.
The text was updated successfully, but these errors were encountered: