Skip to content

android: decode graph patches off the main thread during restore - #58

Merged
tiensonqin merged 1 commit into
mainfrom
devin/1791567605-launch-bg-patch
Oct 10, 2026
Merged

tiensonqin merged 1 commit into
mainfrom
devin/1791567605-launch-bg-patch

Conversation

@tiensonqin

Copy link
Copy Markdown
Contributor

Summary

Cold-launch profiling on the 1000-journal/100-block seeded graph showed backend.applyJson (JSON parse + LuiRetainedTree mutation) running on the main thread for 464ms on a 461KB graph patch — the largest single contributor to the "Skipped 75+ frames" stall between authentication_published and journals_ui_ready.

applyCoreResponse now runs bridge.applySnapshot + applyPatch inside withContext(patchDispatcher) where patchDispatcher = Dispatchers.Default.limitedParallelism(1): decode + tree mutation happen off the main thread while patch ordering stays serial (the dispatcher is single-threaded, so concurrent applyCoreResponse / onPatch calls still apply in order). Publishing stays safe — LuiBackend.publish only writes Compose snapshot state, which is designed for cross-thread writes.

Also adds a GraphLifecycle timing log (applyJson took Xms for N chars, only when >20ms) — this is what attributed the stall and is useful for future launch profiling.

Measured on the emulator (1000×100 graph): the 461KB patch moved from 464ms on main to 289ms on a background worker; total journals_ui_ready is bounded by the remaining Compose frame, which this also unblocks.

Link to Devin session: https://app.devin.ai/sessions/0f103e5f2f014fa887d43048a7c1200f
Open in Devin Desktop: https://app.devin.ai/desktop/session/0f103e5f2f014fa887d43048a7c1200f?variant=devin
Requested by: @tiensonqin

@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@tiensonqin
tiensonqin merged commit ccd2107 into main Oct 10, 2026
1 check passed
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