Repository navigation
perf(persistence): stop rewriting redundant bytes in the profile store - #18317
Conversation
Two kinds of byte in orca-data.json were provably redundant. Both are paid on every debounced save (full re-serialize) and every launch (full re-parse). 1. The renderer's host split handed one global-field template to EVERY host, so local's browserUrlHistory/workspaceDocHistory were copied verbatim into each non-local partition. That is a write-side regression undoing #18161's load-time drop: the load path removed the replicas, the next full snapshot write put them back. Non-local slices now get a template without the fields the merge only ever reads off 'local', and both the host write and the serializer strip the residue. 2. mergeWorktreeMetaForWrite materializes all ten linked* slots plus isArchived/isPinned on every metadata row, so a 1,200-workspace store carried ~534 KB of "field":null pairs across worktreeMeta and worktreeMetaByIdentity. The serializer omits slots still at their default and normalizeWorktreeLinkedItemMetadata re-fills them at load, so in-memory state is unchanged. Measured on a fixture sized like the reporting install (10 hosts, 1,200 metadata rows, 200 history entries): 1,445,276 -> 643,238 bytes per save (-55.5%), 164,250 -> 3,411 bytes structured-cloned per persistWorkspaceSessionByHost across 9 non-local hosts, launch JSON.parse 2.00 ms -> 1.37 ms.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (12)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe change reduces persisted state redundancy. Worktree metadata fields with fixed defaults are omitted during serialization and restored during loading. Host partitions no longer store local-owned global session fields when the local slice already contains them. Renderer partition templates and main-process persistence use the shared filtering helpers. Tests cover compact output, round-tripping, size reduction, write stability, and host-slice merging. Merge Risk: ⚪ Minimal · up to The persistence compaction preserves the required local and partitioned session data paths, with no unresolved merge-blocking risk identified. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description provides detailed scope, rationale, measurements, compatibility analysis, and test results, but it omits required template content, including a Linked Issue, explicit Visual Proof with N/A and a reason, and the required checklist sections.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Worktree metadata default omission (part C) — the serializer drops any
WorktreeMetaslot equal to its fixed default (linked*: null,isArchived/isPinned: false) andnormalizeWorktreeLinkedItemMetadatare-fills them at load, withWORKTREE_META_PERSISTED_DEFAULTSas the single source both sides spread. - Session-partition redundant globals (part A) — non-local host partitions stop carrying local-owned
browserUrlHistory/workspaceDocHistory, enforced at three layers (renderer split template,setHostWorkspaceSession, serializer backstop) via helpers moved intosrc/shared/. - Tests — new
persisted-state-redundancy.test.tsand split/partition test cases pin the round-trip equality, the safety gates, and the byte-stability of a quiet flush.
The omission/fill symmetry holds (omit only when value equals default, fill only when undefined), forward safety is guaranteed because the fill runs over both metadata maps before any consumer reads them, and the downgrade path stays lossless since mergeWorktree/getLinkedWorkItemMetadata coerce every omitted slot with ?? null/?? false. The partition strip only fires when local already holds the field, so the merge's fallback remains live — including the workspaceDocHistory-optional case. The deliberate normalizedUrl exclusion and the separate duplicate-map follow-up are both correctly reasoned.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
stablyai#18317) Two kinds of byte in orca-data.json were provably redundant. Both are paid on every debounced save (full re-serialize) and every launch (full re-parse). 1. The renderer's host split handed one global-field template to EVERY host, so local's browserUrlHistory/workspaceDocHistory were copied verbatim into each non-local partition. That is a write-side regression undoing stablyai#18161's load-time drop: the load path removed the replicas, the next full snapshot write put them back. Non-local slices now get a template without the fields the merge only ever reads off 'local', and both the host write and the serializer strip the residue. 2. mergeWorktreeMetaForWrite materializes all ten linked* slots plus isArchived/isPinned on every metadata row, so a 1,200-workspace store carried ~534 KB of "field":null pairs across worktreeMeta and worktreeMetaByIdentity. The serializer omits slots still at their default and normalizeWorktreeLinkedItemMetadata re-fills them at load, so in-memory state is unchanged. Measured on a fixture sized like the reporting install (10 hosts, 1,200 metadata rows, 200 history entries): 1,445,276 -> 643,238 bytes per save (-55.5%), 164,250 -> 3,411 bytes structured-cloned per persistWorkspaceSessionByHost across 9 non-local hosts, launch JSON.parse 2.00 ms -> 1.37 ms.

ELI5
Orca writes its whole
orca-data.jsonfrom scratch every time anything changes (1 s debounce, 5 s max wait) and reads the whole thing back at launch. On a heavy install that file is 4.2 MB. A big slice of those bytes said nothing: metadata rows spelled out"linkedGitLabMR":nulltwelve times over for ~1,200 workspaces, and three of ten per-host session partitions carried a byte-identical photocopy of the browser history that only thelocalpartition is ever read for.This deletes those bytes on write and reconstructs them on read, so nothing in memory changes — the app just stops paying to write and re-read the same nulls a hundred times a session.
What was happening
A — the renderer split was re-injecting global session fields into every non-local partition. This is a write-side regression that undid #18161's load-side fix.
splitWorkspaceSessionByHostbuilt onetemplateholding allGLOBAL_WORKSPACE_SESSION_FIELDSand handed that same template toensureSlicefor every host, not justlocal.setHostWorkspaceSessionstored it verbatim.mergeWorkspaceSessionsFromHostsreads globals fromlocalfirst and only falls back to another slice when local lacks them — which cannot happen, because the template always fillslocal. So every non-local copy was bytes no read could reach.#18161 added a load-time drop in
parseWorkspaceSessionsByHostIdthat removed the replicas on the way in. But the very next full snapshot write put them straight back, because the split still seeded them. On the reporting install that was 3 of 10 partitions each holding a byte-identical 66,178 B replica of local'sbrowserUrlHistory(verified===), 198,534 B / 4.7% of the file, re-serialized on every save, re-parsed on every launch, and structured-cloned over IPC once per host on everypersistWorkspaceSessionByHostand quit snapshot. It grows linearly with the number of runtime hosts ever used.Fixed in three places so the drop cannot be undone again: the split gives non-local slices a template without
HOST_PARTITION_REDUNDANT_GLOBAL_FIELDS,setHostWorkspaceSessionstrips them from any payload that still carries them, and the serializer sweeps the partition map as a backstop (the load path re-seeds each partition's[]default, which was itself being written back per host).C — ~11,450
"field":nullpairs across the two metadata maps.mergeWorktreeMetaForWritematerializes all tenlinked*slots plusisPinned/isArchivedon every row at creation, even when null. Measured on the real file: 266,977 B inworktreeMeta+ 266,810 B inworktreeMetaByIdentity= 533,787 B, 12.6% of the whole file, per save and per launch parse.The serializer now omits any slot still equal to its default;
normalizeWorktreeLinkedItemMetadata— which already walks every row of both maps at load — re-fills them. The default table (WORKTREE_META_PERSISTED_DEFAULTS) is now the single sourcecreateDefaultWorktreeMetaspreads, so the omit set and the fill set cannot drift. Only genuinely constant defaults are in it:instanceIdandsortOrderare minted per row and stay written.B —
normalizedUrlduplicatingurlinbrowserUrlHistory— dropped, deliberately.19,641 B of
browserUrlHistory's 66,569 B arenormalizedUrlvalues byte-identical tourl, and the load path already recomputesnormalizedUrlfromurlunconditionally (browserHistoryEntriesSchema→normalizeBrowserHistoryEntries), so omitting it would be lossless for this build. It fails the downgrade half of the hard constraint: the entry schema issalvagingArray(browserHistoryEntrySchema)withnormalizedUrl: z.string()required, so an older build silently drops every history entry that omits the field and then rewrites the file without them — real, unrecoverable user data loss, and there is no coercion layer to save it the waymergeWorktreesaves C. 0.46% of the file is not worth that. Not shipped.Measurement
Realistic fixture built to the reported install's shape: 10 hosts (local + 9 runtime, 3 carrying the history replica), 1,200
worktreeMetarows, 1,191worktreeMetaByIdentityrows, 200 browser history entries. Driven through the realStore; "before" is the same loaded state re-expanded to the old on-disk shape, so the delta is the redundancy alone and not fixture noise.Serialized bytes per save
worktreeMetaworktreeMetaByIdentityworkspaceSessionsByHostIdBytes structured-cloned per
persistWorkspaceSessionByHost, 9 non-local hosts: 164,250 → 3,411 (−97.9%).Launch
JSON.parse, median of 25: 2.00 ms → 1.37 ms (−31%), plus the same proportion off thereadFileSyncand off everywriteFile+fsyncon the save path.Projected onto the reporting user's 4,243,739-byte file using its own per-field measurements: 533,787 B (C) + ~198,948 B (A) ≈ 733 KB, 17.3% removed from every save and every launch parse. The fixture removes 268 B/row from metadata versus the 224 B/row measured on the real file, so the projection uses the real number and is conservative.
Negative user-facing trade-offs
None found. The specific claims:
Round trip.
load(save(state))deep-equals the pre-save state for every field touched, asserted directly inpersisted-state-redundancy.test.tsover the full fixture:getAllWorktreeMeta(), the local session, and all nine host sessions. The load-side fill lands in the same change as the omission, sonullnever becomesundefinedfor a consumer doing=== null. A second flush is byte-identical, so a quiet app does not churn the file.Forward compatibility. A file written by the OLD serializer and a file written by the NEW one load to identical in-memory state — its own test. Absence and the default carry the same meaning, and no non-default value is ever omitted.
Downgrade. A file this build writes, read by an older build with no fill:
parseWorkspaceSessionsByHostIdalready drops these fields at load (perf(persistence): build the state file once per save instead of seven times #18161) and re-seeds each partition's default from its own defaults spread. It never reads them off a non-local partition — that is the gateworkspace-session-partitions.test.tsenforces per field. Nothing to lose.WorktreeMetainto theWorktreethe app actually reads already coerces each omitted slot, in code that is onmaintoday and unchanged here —mergeWorktree(meta?.linkedIssue ?? null,isArchived ?? false,isPinned ?? false),getLinkedWorkItemMetadata(?? nullfor all seven optional linked fields),folder-workspace-model,runtime-folder-workspace,runtime-worktree-ps-summaries. Every raw-meta reader in main goes through?.field ?? null, a truthiness check, or aisLinkedIssueNumber-style type guard. An older build therefore builds the sameWorktreeobjects. Then it rewrites the file with the fields still absent (JSON.stringifydropsundefined), and re-upgrading re-fills them — no data lost either direction.Not touched, deliberately:
SAVE_DEBOUNCE_MS/SAVE_MAX_WAIT_MSare unchanged — raising them trades crash-window state loss for bytes.copyFile; left alone.Risk & verification
pnpm tcclean.pnpm run check:code-quality:changedclean (0 new findings across 12 files).Every test in the touched areas runs green, plus the whole of
src/main/persistence,src/renderer/src/lib, and the session schema suites: 582 files / 5,726 tests passing. (persistence-async-write-syscalls.test.tstimed out once at 30 s under full-suite parallelism and passes in 27.6 s standalone — pre-existing headroom, unrelated.)New tests, each verified to fail without its fix:
workspace-session-host-split.test.ts→ never replicates a local-owned global onto a non-local slice: no non-local slice carries anyHOST_PARTITION_REDUNDANT_GLOBAL_FIELDSafter a split, and the merge still returns local's value. Fails onmain.persisted-state-redundancy.test.ts→ round-trips a legacy-shaped file to identical in-memory state and a smaller file: full-size fixture; asserts the refill ran, that only rows holding a real value keep a slot, that no partition on disk carries a redundant global, an apples-to-apples size drop, deep equality acrossload(save(…)), and byte-stability of the next flush. Fails without either the serializer omission or the load-side fill.persisted-state-redundancy.test.ts→ loads an old-serializer file and a new-serializer file to the same state. Fails without the load-side fill.Existing
workspace-session-partitions.test.tsstill re-checks both safety gates for every field inHOST_PARTITION_REDUNDANT_GLOBAL_FIELDS(must be'global', must be'none'inWORKSPACE_SESSION_WORKTREE_REFERENCE_KIND); the constant just moved tosrc/shared/so the renderer split can share it.Separately-scoped follow-up, not done here: 1,191 of the 1,193
worktreeMetarows are byte-identical duplicates ofworktreeMetaByIdentityrows, another ~20% of the file. Dropping the legacy map is a persisted-schema change with a downgrade hazard that this PR's constraints do not permit: an older build reads onlyworktreeMetaand would show zero workspace metadata. It needs its own migration and a deprecation window.