Repository navigation
perf(main): release startup allocations held by journal sentinel - #27342
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to This change adjusts journal handling for null resolver results without swallowing ordinary failures. No actionable merge-blocking risk remains. Pre-merge checks |
|
Credit to outof-place for identifying the retention and proposing the focused fix in #27335. Independently validated 15.19 MiB of collectible startup allocations. Co-authored-by: outof-place <[email protected]>
1d2d7ed to
7c7c3ec
Compare
ELI5
An internal journal marker kept Orca's startup code and bundle-read buffer in memory for the whole session. Creating the marker only when needed lets the garbage collector free those startup allocations, without changing journal results. Process memory was not measured to drop; see Testing.
What Changed
Replace the module-level Error with a private Error class instantiated when a queued resolver returns null. Null still writes no row, returns null, and allows later writes to proceed. Other errors still reject with the original error object.
Why
A module-level Error captures the bundle-loading stack, and V8 retains the functions and loader context in those frames until the stack is formatted. A fresh Error avoids capturing startup frames. This adds one short allocation on the no-result path and avoids a throwaway stack read or a non-Error thrown value.
Credit to @outof-place for identifying the retention and proposing the fix in #27335. This adopts that focused change and adds behavior tests. Those tests also pass on the old code. #27375 adds the test that fails if a shared error object comes back.
Linked Issue
No linked issue. Replaces #27335 following independent performance review.
Visual Proof
N/A: journal results and UI behavior are unchanged.
Testing
The author ran one before/after heap comparison of the same 9.51 MB production main bundle: Electron 43.7.5 on macOS arm64, headless
--serve, isolated empty profiles,ORCA_BACKGROUND_LAUNCH=1, and inspector-forced GC. The snapshots are not attached, and the run was not repeated.In that single run, the old Error's stack retained 5,433,248 bytes of compiled startup code, 981,824 bytes of startup bytecode, and the 9,509,416-byte bundle-read buffer. None of the three was retained after the change. The ~15.2 MiB figure is memory the garbage collector can now free. It is not a measured drop in process memory: RSS was noisy and showed no confirmed saving.
The journal write queue and structured session event sink suites passed: 31 tests across 2 files, including no-row/queue-progress and unchanged propagation of a different Error with the same message.
Node typecheck, changed-code quality against
origin/main, focused oxlint, and formatting checks passed. Installed tools were invoked directly because pnpm's automatic install rejects a symlinked dependency directory in this isolated worktree.I manually tested these changes locally (headless production main-process A/B)
Automated tests added/updated, or explained why not below
Review
Review the private marker and its two uses in
journal-item-appender.ts, then the two journal regression cases. Merge risk is low; no negative user-facing trade-offs were found. This does not alter IPC, persistence formats, host authority, or remote behavior.Agent skill upstream boundary
Notes
The change is platform-independent. The measurement ran on macOS; Windows/Linux and SSH journal paths use the same queue and appender. No broad app or native dependency changes are involved.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; focused checks above passed)