Skip to content

Reduce full startup roster writes - #4165

Draft
dr0uleau wants to merge 11 commits into
mainfrom
perf-health/channel-roster-persistence
Draft

dr0uleau wants to merge 11 commits into
mainfrom
perf-health/channel-roster-persistence

Conversation

@dr0uleau

@dr0uleau dr0uleau commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Why

A change to one channel can rewrite the complete startup roster in IndexedDB. Pruning then reads large roster and profile values back into the renderer.

What

Coalesce routine discovery changes into at most one full save every 30 seconds during a steady burst. Keep first saves, signed grants, first channel names, and revocations on their existing prompt path. Prune from keys and byte counts. Skip duplicate sidebar saves after a successful write.

How

Keep the roster and sidebar settings in the existing version 2 row, so older builds can restore and clear the same records. Keep merge and prune inside the storage transaction. Channel restore records the roster version during startup reads. Manual Reload records it too and waits for live discovery before showing channels. A successful save advances the recorded version. An aborted write can retry against that version. Only the current conflicting attempt can record a peer replacement. A signed change that arrives during a pending write stays eligible after that replacement. Once the cooldown ends, a repeat can save the change if the replacement is still current. If a peer emptied the cache, guarded repeats stop. A fresh signed confirmation can still update a queued save. A skipped or evicted preference write remains retryable.

Risk

The last saved snapshot serves offline startup during the cooldown. Signed membership removal saves immediately. Live confirmation of a cached system channel bypasses the cooldown.

Testing

A replay of 20 updates over 10 seconds used 3,752 signed events in a 3.89 MB roster. Chromium and WebKit each went from 20 full writes and 273.4 MB transferred to one full write and 7,782,224 bytes transferred. Pruning read 788 bytes of metadata and zero roster payloads. The byte count uses UTF-8 JSON sizes of IndexedDB values.

The real IndexedDB case replaces the prior mocked mirror-eviction assertion. It also runs the version 2 clear against two populated scopes, inspects raw payloads before any new write, and confirms the other scope remains available. The same case reproduced surviving roster rows on the earlier sharded implementation.

Chromium and WebKit passed 28 startup and persistence cases at 55b89614. The expanded regression failed in both engines on 48845862 and passed on 55b89614. It saves a signed change received during a pending write after a peer replacement. It also keeps the cache empty after a clear, replacement, and second clear.

On fac4618a, both engines reproduced a Reload save that could not retry after an abort and a fresh change that stayed unsaved after a conflict. With the fix, the Reload retry and the save after cooldown both passed. The tests held two guarded writes in IndexedDB and verified that a peer replacement and a later clear survived.

Both engines also retried an aborted revocation while the roster stayed unchanged. They kept the fixes for an earlier peer clear that was undone and three redundant reads after a peer replacement, both reproduced on 9828d5b1. An isolated WebKit run restored the saved conversation and sidebar group before the handshake.

bin/pnpm test:browser tests/browser/startup-persistence.spec.mjs tests/browser/startup.spec.mjs tests/browser/relay-head-persistence.spec.mjs --project chromium --project webkit --no-deps --workers=2

After merging main at 6d4f1107, commit 416b0ff5 passed all 28 Chromium and WebKit cases, including cached startup and cross-tab cache clears. The separate WebKit startup run passed. The replay still used one roster write and 7,782,224 bytes across 20 updates. Pruning read 788 metadata bytes and zero roster payloads. Pre-push passed TypeScript, 12,702 related tests, and the design checks. Human startup confirmation is pending.

Generated with Codex

dr0uleau and others added 4 commits November 20, 2026 17:01
Co-authored-by: Zot <c3aebd34f908628cf72f7f0537da6ec46cec1eb63888805ce915222ed751f17b@buzz.block.builderlab.xyz>
Signed-off-by: Daniel Rouleau <drouleau@squareup.com>
Co-authored-by: Zot <c3aebd34f908628cf72f7f0537da6ec46cec1eb63888805ce915222ed751f17b@buzz.block.builderlab.xyz>
Signed-off-by: Daniel Rouleau <drouleau@squareup.com>
Co-authored-by: Zot <c3aebd34f908628cf72f7f0537da6ec46cec1eb63888805ce915222ed751f17b@buzz.block.builderlab.xyz>
Signed-off-by: Daniel Rouleau <drouleau@squareup.com>
Co-authored-by: Zot <c3aebd34f908628cf72f7f0537da6ec46cec1eb63888805ce915222ed751f17b@buzz.block.builderlab.xyz>
Signed-off-by: Daniel Rouleau <drouleau@squareup.com>
@dr0uleau dr0uleau changed the title Persist startup roster changes incrementally Reduce full startup roster writes Nov 21, 2026
dr0uleau and others added 7 commits November 20, 2026 18:19
Co-authored-by: Zot <c3aebd34f908628cf72f7f0537da6ec46cec1eb63888805ce915222ed751f17b@buzz.block.builderlab.xyz>
Signed-off-by: Daniel Rouleau <drouleau@squareup.com>
Co-authored-by: Zot <c3aebd34f908628cf72f7f0537da6ec46cec1eb63888805ce915222ed751f17b@buzz.block.builderlab.xyz>
Signed-off-by: Daniel Rouleau <drouleau@squareup.com>
Co-authored-by: Zot <c3aebd34f908628cf72f7f0537da6ec46cec1eb63888805ce915222ed751f17b@buzz.block.builderlab.xyz>
Signed-off-by: Daniel Rouleau <drouleau@squareup.com>
Co-authored-by: Zot <c3aebd34f908628cf72f7f0537da6ec46cec1eb63888805ce915222ed751f17b@buzz.block.builderlab.xyz>
Signed-off-by: Daniel Rouleau <drouleau@squareup.com>
Co-authored-by: Zot <c3aebd34f908628cf72f7f0537da6ec46cec1eb63888805ce915222ed751f17b@buzz.block.builderlab.xyz>
Signed-off-by: Daniel Rouleau <drouleau@squareup.com>
Co-authored-by: Zot <c3aebd34f908628cf72f7f0537da6ec46cec1eb63888805ce915222ed751f17b@buzz.block.builderlab.xyz>
Signed-off-by: Daniel Rouleau <drouleau@squareup.com>
Co-authored-by: Zot <c3aebd34f908628cf72f7f0537da6ec46cec1eb63888805ce915222ed751f17b@buzz.block.builderlab.xyz>
Signed-off-by: Daniel Rouleau <drouleau@squareup.com>

This branch has not been deployed

No deployments
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