Skip to content

fix(plugins): yield to a macrotask between vault snapshot chunks#190

Open
rotecodefraktion wants to merge 1 commit into
ipapakonstantinou:devfrom
rotecodefraktion:fix/plugin-snapshot-yield
Open

fix(plugins): yield to a macrotask between vault snapshot chunks#190
rotecodefraktion wants to merge 1 commit into
ipapakonstantinou:devfrom
rotecodefraktion:fix/plugin-snapshot-yield

Conversation

@rotecodefraktion

Copy link
Copy Markdown

What changed

streamVaultSnapshot yielded between chunks with queueMicrotask. The
microtask queue drains before the browser gets a chance to paint, so the
entire chunk loop effectively ran as a single blocking task on the host
main thread. Switched to the existing yieldToMain() helper
(scheduler.postTask with a 0ms-timeout fallback) — a real macrotask
boundary — so the UI can repaint between chunks.

Why

On large vaults the snapshot stream froze the host UI until the loop
finished. Yielding to a macrotask keeps the app responsive while the
snapshot streams to plugins.

How it was tested

  • npm run lint
  • npm run typecheck (no errors introduced by this change)
  • npm testvaultSnapshotCache, syncPullWritesSnapshot, largeVaultPerf pass
  • npm run build
  • Sync change? n/a
  • UI change? n/a (behavioral perf fix, no visual change)

Notes

Single-file change (src/plugins/vaultSnapshot.ts, +7/-4). Reuses the
already-present yieldToMain() from @/utils/bootTrace.

streamVaultSnapshot yielded with queueMicrotask, which drains before any
render — the whole chunk loop ran as one blocking task on the host main
thread. Use the existing yieldToMain() helper (scheduler.postTask / 0ms
timeout) so the UI can repaint between chunks.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant