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(store-sync): wait for idle after each chunk of logs in a block #2254

Merged
merged 6 commits into from
Feb 16, 2024

Conversation

Kooshaba
Copy link
Contributor

don't ask me why or how, but adding sleep(1) after calling the storageAdapter made hydration updates show up in the client. i was going crazy trying to figure out why i wasn't receiving them in the main thread, but then remembered having a similar problem in DF with how async calls were being handled. if someone actually knows the mechanism that is being abused here lmk and we can come up with a less obscure solution.

also once i started receiving updates i realized the % calculation was wrong, so fixed that too.

getting these updates is important so i can properly benchmark how long hydration takes on the sky strife end. my manual calculations on my pc are ~5 seconds.

Copy link

changeset-bot bot commented Feb 12, 2024

🦋 Changeset detected

Latest commit: a0cd05c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@latticexyz/store-sync Major
@latticexyz/dev-tools Major
@latticexyz/store-indexer Major
@latticexyz/abi-ts Major
@latticexyz/block-logs-stream Major
@latticexyz/cli Major
@latticexyz/common Major
@latticexyz/config Major
create-mud Major
@latticexyz/ecs-browser Major
@latticexyz/faucet Major
@latticexyz/gas-report Major
@latticexyz/network Major
@latticexyz/noise Major
@latticexyz/phaserx Major
@latticexyz/protocol-parser Major
@latticexyz/react Major
@latticexyz/recs Major
@latticexyz/schema-type Major
@latticexyz/services Major
@latticexyz/solecs Major
solhint-config-mud Major
solhint-plugin-mud Major
@latticexyz/std-client Major
@latticexyz/std-contracts Major
@latticexyz/store-cache Major
@latticexyz/store Major
@latticexyz/utils Major
@latticexyz/world-modules Major
@latticexyz/world Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@holic
Copy link
Member

holic commented Feb 12, 2024

Wonder if we should wait on every block or some number of iterations. Just thinking about how hydrating thousands of blocks will take significantly longer to complete if we have to wait for idle on each block.

@Kooshaba Kooshaba requested a review from holic February 13, 2024 03:32
@holic holic changed the title fix: send hydration updates to main thread and change loading % calculation feat(store-sync): wait for idle after each chunk of logs in a block Feb 13, 2024
@@ -145,11 +145,16 @@ export async function createStoreSync<TConfig extends StoreConfig = StoreConfig>
await storageAdapter({ blockNumber, logs: chunk });
onProgress?.({
step: SyncStep.SNAPSHOT,
percentage: ((i + chunk.length) / chunks.length) * 100,
percentage: (i / chunks.length) * 100,
Copy link
Member

@holic holic Feb 13, 2024

Choose a reason for hiding this comment

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

I think both of these code snippets might be wrong. The original intent of this was to have the percentage represent the completed state of the chunk (since we called storageAdapter above this).

I think the deleted snippet was meant to be ((i * chunkSize + chunk.length) / logs.length) * 100

And the new snippet is changing this to the "start" of the chunk (rather than "end"), so this probably should be ((i + 1) / chunks.length) * 100

@holic
Copy link
Member

holic commented Feb 15, 2024

waiting on #2264 just so we can have a test that this does what we expect

Copy link
Contributor

@yonadaa yonadaa left a comment

Choose a reason for hiding this comment

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

I added a spec and tested on Sky Strife testnet, works great 👍

Screen.Recording.2024-02-16.at.11.24.43.mov

@holic holic merged commit 997286b into main Feb 16, 2024
11 checks passed
@holic holic deleted the kooshaba/hydration-updates branch February 16, 2024 11:55
Kooshaba added a commit that referenced this pull request Mar 11, 2024
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