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

refactor: Optimize accounts/{accountId}/staking-payouts blocking query complexity #372

Merged
merged 11 commits into from
Jan 7, 2021

Conversation

emostov
Copy link
Contributor

@emostov emostov commented Dec 20, 2020

Likely closes: #367

In the previous iteration of AccountsStakingPayoutsService we had M * N batched queries (read: queries await-ed within aPromise.all) , where M is the depth of eras and N is maximum number of validators nominated by address at any given era.

This PR dramatically reduces the endpoint complexity and response time by always only waiting for two batches of queries to resolve. So we have simplified the blocking query complexity from O(m*n) => O(1).

We achieve this by taking advantage of the fact that we can dynamically build arrays of promises wrap them in await Promise.all.

Below is a picture of Sidecar logs, left is master and right is this branch (look at the end of log message for response time in milliseconds):

Screen Shot 2020-12-19 at 9 07 59 PM

Copy link
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10x improvement! 🍰

src/services/accounts/AccountsStakingPayoutsService.ts Outdated Show resolved Hide resolved
src/services/accounts/AccountsStakingPayoutsService.ts Outdated Show resolved Hide resolved
src/services/accounts/AccountsStakingPayoutsService.ts Outdated Show resolved Hide resolved
src/services/accounts/AccountsStakingPayoutsService.ts Outdated Show resolved Hide resolved
src/services/accounts/AccountsStakingPayoutsService.ts Outdated Show resolved Hide resolved
@emostov emostov requested a review from TarikGul January 7, 2021 01:04
@TarikGul
Copy link
Member

TarikGul commented Jan 7, 2021

lgtm

@emostov emostov merged commit b3cbf61 into master Jan 7, 2021
@emostov emostov deleted the zeke-optimizing-payouts branch January 7, 2021 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I7 - Optimization 🚴 Make Sidecar drive faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Staking-payouts with large depths not successful
3 participants