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

Curvejs Performance: (Router swap) #312

Closed
amytsang opened this issue Apr 22, 2024 · 2 comments · Fixed by #385
Closed

Curvejs Performance: (Router swap) #312

amytsang opened this issue Apr 22, 2024 · 2 comments · Fixed by #385
Assignees

Comments

@amytsang
Copy link
Contributor

amytsang commented Apr 22, 2024

Source code: https://github.com/curvefi/curve-js/blob/master/src/router.ts

Router performance profile is in the following screenshot (in the comments).

Priority topic, since router is the landing page and needs to be as fast as possible.

Solutions involve optimising the router.js code.

@amytsang
Copy link
Contributor Author

Image

For every router swap, I called the following 3 functions: (one of these functions is making massive amounts of calls, which degrades UI performance to the point it is not usable. Need to figure out a way to move these away from the main thread.

curve.router.getBestRouteAndOutput(fromAddress, toAddress, fromAmount),
curve.router.expected(fromAddress, toAddress, fromAmount),
curve.router.priceImpact(fromAddress, toAddress, fromAmount),

@bout3fiddy
Copy link

For reference,

  1. getBestRouteAndOutput is the main routing logic (uses breadth first search), returns an array of pools through with a swap should go through to go from input token to output token specified by the user.
  2. expect gets the expected output from the swap by calling get_dy, or get_dy_underlying etc. of each individual pool in the calculated route.
  3. price impact checks the difference between expected output calculated in step 2 versus the same for a very very small amount.

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 a pull request may close this issue.

5 participants