-
Notifications
You must be signed in to change notification settings - Fork 476
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
Optimize division-related Integer operations #6391
Labels
Comments
It's very likely a drop in the ocean, because you don't just execute monster
Most of that is pretty cheap, but is still overhead and I really doubt that 15 extra nanoseconds gonna make a difference. I think this is very low-priority, so I'm going to triage it as such. |
effectfully
added
Low priority
Doesn't require immediate attention
Builtins
Performance
status: triaged
and removed
status: needs triage
GH issues that requires triage
labels
Aug 8, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Describe the feature you'd like
The division-related primops in Plutus are essentially direct copies of their GHC counterparts. While this is a good thing in general, there are some inefficiencies we inherit as a result of this.
The biggest example is that (for positive values at least),
quot
operations do not reduce to right shifts, even on constant arguments:This is a non-trivial difference in both time and space, and while the numbers appear large, they are not particularly big for
Integer
s. This inefficiency extends torem
operations, which could be implemented with masking.While this appears to be of minor benefit, we observe that
quot n (2 ^ k * d) = quot (quot n (2 ^ k)) d
for positive numbers. Furthermore, as per #6390 , we can 'decompose' numbers which have a power of 2 in their prime factorization fairly easily (counting trailing bits), which, combined with the above observation, could give us considerable performance. This also relates to the cases raised in #6390, just in the other direction.Similar techniques could be applied to
div
andmod
as well (or rather, our definitions of them) to produce improvements.Describe alternatives you've considered
Currently, these optimizations cannot be obtained. Even using CIP-121, CIP-122 and CIP-123 operations, due to the currently-quadratic cost of CIP-121 conversions, this would drown out any benefits we're likely to see. Even though CIP-121 operations could be linear, this would still be an unavoidable pair of copies, due to pinnedness issues in
ghc-bignum
.The text was updated successfully, but these errors were encountered: