Skip to content

perf(main): release startup allocations held by journal sentinel - #27342

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-session-error-no-retention
Oct 11, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-session-error-no-retention

Conversation

@nwparker

@nwparker nwparker commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1

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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; focused checks above passed)

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 62c95569-aa41-45d5-b362-1fd683f18b73


📥 Commits

Reviewing files that changed from the base of the PR and between 77d5de1 and 1d2d7ed.



📒 Files selected for processing (2)
  • src/main/native-chat/agent-session-journal/journal-item-appender.ts
  • src/main/native-chat/agent-session-journal/journal-write-queue.test.ts


Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.




📝 Walkthrough
📝 Walkthrough

Walkthrough

appendResolved now uses a fresh NothingResolvedError when the resolver returns null. It treats instances of that class as no-write results. Tests check that null results leave the journal sequence unchanged, that unrelated errors with the same message propagate, and that a later append succeeds in both cases.



Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 1d2d7

This change adjusts journal handling for null resolver results without swallowing ordinary failures. No actionable merge-blocking risk remains.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check Warning The description is detailed and covers the change, rationale, testing, scope, and checklist. However, the required Linked Issue section states "No linked issue" and does not provide an actual issue li… Add a valid linked issue reference in the required Linked Issue section, such as the issue addressed by this change. If #27335 is the relevant issue, link it explicitly and explain its relationship to this pull request.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly identifies the performance change: releasing startup allocations held by the journal sentinel.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.


Full details: Description check

Explanation

The description is detailed and covers the change, rationale, testing, scope, and checklist. However, the required Linked Issue section states "No linked issue" and does not provide an actual issue link.




✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR



  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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]>
@nwparker
nwparker force-pushed the nwparker/perf-session-error-no-retention branch from 1d2d7ed to 7c7c3ec Compare October 11, 2026 03:44
@nwparker
nwparker merged commit bc02f3c into main Oct 11, 2026
29 checks passed
nwparker added a commit that referenced this pull request Oct 11, 2026
…27375)

Follow-up to #27342: the existing tests also pass on the old module-level
Error, so add one that fails if a single error object is reused.
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