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

Reduce calculateAmountReceived latency #3905

Closed
1 task
alexwhte opened this issue Mar 30, 2023 · 15 comments · Fixed by #3999
Closed
1 task

Reduce calculateAmountReceived latency #3905

alexwhte opened this issue Mar 30, 2023 · 15 comments · Fixed by #3999
Assignees
Labels
Enhance 🧘 Issue type: Enhancement Request

Comments

@alexwhte
Copy link
Contributor

alexwhte commented Mar 30, 2023

Problem

Connext is not even showing in results 30% of the time (est) because our API takes too long
See analysis in here #3895

Based on these initial profiling results, calculateSwap is the biggest contributor of latency. We call it (up to) 2 times per call, once to calculate origin swap and once to calculate destination swap.
In the calculateSwap function, the direct contract call here contains the majority of the latency:
const minAmount = await connextContract.calculateSwap(key, tokenIndexFrom, tokenIndexTo, amount);

Impact

25% of our volume last week came from LiFi alone.
We are recommended 40% of the time when shown, but only even a shown option 70% of the time

CalculateSwap is involved in 1665 ms (63%) of the latency

TOTAL for calculateAmountReceived: 2642.678041934967 ms
awaited promises (getPool, getCanonicalTokenId, isNextAsset): 677.4156659841537 ms
calculateCanonicalKey: 3.511583924293518 ms
getAssetsDataByDomainAndKey: 0.15845799446105957 ms
origin-calculateSwap: 722.9010410308838 ms
destination-getPool: 293.92433309555054 ms
getActiveLiquidity: 0.01979196071624756 ms
awaited promises (calculateSwap, getActiveLiquidity): 942.6627079248428 ms

Proposed Solution

How well do you think a cache would do here, that updates by reading the contract multiple times a second?
NOTE: Need to decide which calls we optimize for if not just calculateSwap

Acceptance Criteria

From an end user perspective, the below criteria must be met to consider this done:

  • Connext is always
@alexwhte alexwhte changed the title Reduce Reduce calculateAmountReceived latency Mar 30, 2023
@alexwhte alexwhte added Enhance 🧘 Issue type: Enhancement Request integrations Pri labels Mar 30, 2023
@alexwhte
Copy link
Contributor Author

Complexity: 13
See the discussion in Backlog Prio 1

Powered by Parabol

@alexwhte
Copy link
Contributor Author

Urgency: 4
See the discussion in Backlog Prio 1

Powered by Parabol

@alexwhte
Copy link
Contributor Author

Urgency: 3
See the discussion in Backlog Prio 1

Powered by Parabol

@alexwhte alexwhte removed the Pri label Apr 5, 2023
@just-a-node just-a-node added the Pri label Apr 6, 2023
@alexwhte
Copy link
Contributor Author

alexwhte commented Apr 6, 2023

Complexity: 21
See the discussion in Sprint Poker #​​26

Powered by Parabol

@alexwhte
Copy link
Contributor Author

alexwhte commented Apr 6, 2023

Impact: 4
See the discussion in Sprint Poker #​​27

Powered by Parabol

@alexwhte
Copy link
Contributor Author

alexwhte commented Apr 6, 2023

Urgency: 4
See the discussion in Sprint Poker #​​27

Powered by Parabol

@rhlsthrm rhlsthrm removed the Pri label Apr 12, 2023
@alexwhte
Copy link
Contributor Author

Complexity: 21
See the discussion in Sprint Poker #​​29

Powered by Parabol

@alexwhte
Copy link
Contributor Author

Impact: 5
See the discussion in Sprint Poker #​​30

Powered by Parabol

@alexwhte
Copy link
Contributor Author

Urgency: 3
See the discussion in Sprint Poker #​​30

Powered by Parabol

@liu-zhipeng liu-zhipeng self-assigned this Apr 17, 2023
@liu-zhipeng
Copy link
Contributor

#3895 (comment)

@alexwhte how can i get these metrics on my local side?

@just-a-node
Copy link
Collaborator

@liu-zhipeng I used performance.mark() API to get these splits within the function.

@rhlsthrm rhlsthrm removed the Pri label Apr 18, 2023
@rhlsthrm
Copy link
Collaborator

Working on bypassing RPC call for calculating amount received.

@liu-zhipeng
Copy link
Contributor

image

Calculated receive amount in 2ms in locally based from pool information instead of calling rpc

@liu-zhipeng liu-zhipeng linked a pull request Apr 18, 2023 that will close this issue
7 tasks
@rhlsthrm
Copy link
Collaborator

Fixing coverage of tests.

@rhlsthrm
Copy link
Collaborator

Ready for merge into main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhance 🧘 Issue type: Enhancement Request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants