Skip to content
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

feat: use fast exponentiation for better perf #211

Merged
merged 5 commits into from
Apr 2, 2024

Conversation

IvanVergiliev
Copy link
Contributor

This PR replaces two functions that cause a lot of slowness due to running a lot of BigDecimal operations with more efficient versions.

  • fastExponentiation replaces the bigDecimalExponated with an implementation of exponentiation by squaring in order to get the number of multiplications from O(N) to O(log N) on the power. This is particularly effective for large powers in the hundreds or thousands.
  • exponentToBigDecimal replaces the 10^N computation with a string-based implementation. This sounds weird at first, but it helps with performance because it replaces N calls to BigDecimal operations with only one at the end.

A possible further optimization to the fastExponentiation is to expose that as a WebAssembly host function at the graph-node level. This should help optimize performance further by removing the need to pass BigDecimal values back and forth between the AssemblyScript handler function and the Rust BigDecimal.times host function.

@mzywang mzywang merged commit 0eeb07a into Uniswap:main Apr 2, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants