-
Notifications
You must be signed in to change notification settings - Fork 608
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 powApprox
#56
Comments
@ValarDragon thoughts? |
I'm strongly in favor of a mutable decimal. However I think in the end-state, we shouldn't be making a new type, but instead be adding I am in favor of adding a MutativeDec type for now though. |
I also think theres a lot we can do to just have faster code for expected "normal" exponents we'll run into. |
I'm also generally very unconvinced about the quality of the current binomial approximation we use (which is identical to what is in balancer). I think post-launch we should be looking into precomputed table based methods |
Should this be #post-launch? |
Yeah, but we should probably do it soon after launch, since this does control the gas of the chain. (We can build this as a non-state breaking update anyway). The #62 approach is complementary, and gets us more for the common use cases. |
Currently
powApprox
undergamm/keeper/math.go
is using a lot of resources.BenchmarkPow()
test will measure the performance of the function. I’m ran 10 small pows on my MBP(2018/2.3GHz 8 Core i9/16GB RAM) and this was the result I got:Because multithreading is not used, the number of CPU cores shouldn’t matter, but it does require a lot of memory space and allocation.
Currently, the function is used to find a rational number exponent of a rational number. However, this seems to require too many loops so speed and memory becomes an issue.
The current implementation uses an expanded recursion function to find the binomial series so using multithreading will be difficult.
As for the memory, Cosmos-SDK’s
sdk.Dec
is immutable so it’s safer to use, but requires memory allocation every single time so it uses a lot of memory. To run some tests on the benefits, I’ve created a temporarymutable dec
type under thegamm-math-perf
branch.The following are the results:
It seems like memory allocation and memory use has definitely decreased. So the speed is a bit faster. But using a mutable dec will require extra caution, and because it’s different from Cosmos-SDK’s
sdk.Dec
each must be managed separately and must be well checked for bugs.Pros:
Cons:
sdk.Dec
-> may have bugs.The text was updated successfully, but these errors were encountered: