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

[subgraph] lowest hanging fruit to reduce a bit of RPC calls #1955

Closed

Conversation

kasparkallas
Copy link
Contributor

@kasparkallas kasparkallas commented Jun 11, 2024

Why?

To speed up indexing and to reduce indexing time.

What?

Tried to massively reduce RPC calls in the following branch: #1948 but it needs more testing. This is the lowest hanging fruit fix that struck out from that endeavour, which is to not do an RPC call for a balance if it has already been done in the same block.

How?

Add a simple condition to check whether the entity has been updated in the same block.

Other

The fix might not have much effect if the balanceOf calls are somehow efficiently cached in the RPC, although it would still reduce I/O.

@kasparkallas kasparkallas requested a review from d10r June 11, 2024 14:07
@kasparkallas kasparkallas self-assigned this Jun 11, 2024
@kasparkallas kasparkallas requested a review from hellwolf as a code owner June 11, 2024 14:07
@kasparkallas kasparkallas changed the title [subgraph] lowest-hanging fruit to reduce a bit of RPC calls [subgraph] lowest hanging fruit to reduce a bit of RPC calls Jun 11, 2024
@kasparkallas kasparkallas enabled auto-merge June 11, 2024 15:38
@kasparkallas kasparkallas disabled auto-merge June 11, 2024 15:43
@kasparkallas kasparkallas enabled auto-merge June 11, 2024 19:56
@hellwolf
Copy link
Contributor

test failing. is it related?

@kasparkallas kasparkallas disabled auto-merge June 12, 2024 08:15
@kasparkallas
Copy link
Contributor Author

test failing. is it related?

Yep, it's related. It's caused by the fact that when AccountTokenSnapshot is initialized then the updatedAt is immediately set.

Even though every time the entity is initialized, later on the balance function is called outside of it. There are 3 ways to solve it:

  1. Call the balance function when initializing the entity.
  2. Remove the updatedAt update from the initialization
  3. Save a field in style of "balanceLastUpdatedFromRpcAtBlockNumber" onto the entity and use that to check

It's probably best to do 3 as it's the safest and is needed anyway if we are to add more RPC optimizations.

I'll not add this to the next deployment because of this, so I'll close this PR for now and continue with the other optimization PR.

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