Files
orca/src/shared
Neil 0d42e3fc99 perf(persistence): stop double-traversing the persisted session at load (#18458)
* perf(persistence): stop double-traversing the persisted session at load

normalizeLoadedProfileState is the largest measured startup cost that scales
with profile size, and almost all of it is zod-validating the 1.9 MB
workspaceSession blob.

Two redundant traversals removed, with no change to what is accepted:

- The salvage containers wrapped `z.record(z.string(), z.unknown())` /
  `z.array(z.unknown())` around a transform that re-validates every entry
  itself, so zod validated and copied each map and array before the real
  per-entry parse even started. The containers now apply the same guards zod
  applied (`isPlainObject` plus its enumerable-symbol-key rejection,
  `Array.isArray`) and walk the input once.
- The two recursive layout node schemas were plain unions, so every split node
  of every restored terminal and tab-group layout re-tried the leaf branch.
  They discriminate on `type`, which has the same accept and reject set.

Cold parse of a 413-worktree / 801-tab profile: 52.5 -> 45.0 ms CPU
(-14.3%, median of 25 interleaved processes). Steady state: 9.8 -> 7.1 ms.

* test(persistence): pin absence-stays-fatal for the salvaging containers

The comment on salvagingArray claimed a bare container in a z.object shape
would read a missing key as an absence unless wrapped. Not true on zod 4.5.4:
a bare transform sets neither optin nor optout, and handlePropertyResult only
swallows an absent key's issues when a field is both. Assert it instead of
documenting it, and correct the comment.

Also add the .js extension the node16 CLI project needs on the two dynamic
imports these tests added, which broke `pnpm tc`.
2026-09-03 21:15:28 -07:00
..
2026-05-31 05:55:04 -07:00
2026-09-03 17:32:59 -07:00