Skip to content

perf: avoid copying Codex output between saved checkpoints - #26199

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-codex-checkpoint-join-admission
Oct 8, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-codex-checkpoint-join-admission

Conversation

@nwparker

@nwparker nwparker commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Large Codex command output uses less CPU between saved checkpoints. Chat content and publication timing stay the same.

What Changed

Codex already saves streamed text only after enough new text arrives, but it assembled the entire prefix before deciding to skip a checkpoint. It now checks the same threshold against the retained JavaScript string length before assembling that prefix. Final flushes and refused writes still retain and publish all owed text.

The shared coalescer's optional gate accepts a skipped snapshot; refusal and retry still come from its existing sink callback. Claude and the other shared consumer keep the default behavior.

Why

Reuse the existing checkpoint threshold to remove repeated copying without changing streaming intervals, text limits, or journal rows. A new debounce or cache would change timing or add ownership state.

A supported generated 16MiB command stream, delivered in 256 manual 60ms windows through the complete translator and real SQLite journal, reduced timer prefix assembly from 256 joins / 2.156 billion characters to 34 joins / 138 million characters. Seven alternating uninstrumented trials reduced median total synchronous work during those windows from 189.77ms to 83.46ms. Final flush time is excluded from this measurement. The largest single window remained near 9ms, and small controls were mixed. These results establish reduced copying and CPU work; they do not measure heap bytes or desktop/phone typing latency.

Linked Issue

N/A — maintainer performance audit.

Visual Proof

N/A — text, rows, publication cadence, and user interaction remain unchanged.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Temporary frozen-source comparison passed 274 exact control cases and 13 complete real-journal cases. These compare row content, publication order, admission results, snapshots, and timer schedule/cancel/fire traces, including Unicode and truncation, rejected writes/retries, capacity eviction, changed attribution, completion and patch flushes, and unchanged Claude/timeline consumers. Independent journal epoch UUIDs alone are normalized.

Every measured trial verifies final output byte length and SHA256, plus identical journal row and publication counts. Fixture is generated supported output, not a captured private CLI transcript. Local host: macOS/Node. This is platform-independent string accounting with no path, subprocess, execution-host, or wire changes; remote clients receive the same content at the same cadence.

Persistent regression tests fail on the old implementation (two failures, one unchanged retry control passing) and all 161 tests in 16 focused suites pass with the change. Coverage includes the shared coalescer, Codex translator streams, Claude checkpoints, and all provider timeline assembler suites. pnpm tc:node, ordinary/native/anti-slop lint, formatting, max-lines ratchet, and changed-code quality against baseline 4077fb4a8de8 pass. The combined audit branch also passes 3,369 tests in 323 Codex/journal/timeline/coalescer/Claude files, the full project typecheck, and changed-code quality (77 files, zero new findings). Selected CI checks also pass, including all five Node 24 shards, cross-version wire compatibility, relay integration, Linux persistence, and Linux/Windows packaging. The Windows profile-state stall test passed on a job retry after its first run timed out; no unrelated source or test changes were made.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Folder workspaces and SSH/paired execution retain their existing routing. No changes to process status, remote capabilities, client schemas, or payload limits.

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; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 7, 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: e4c65596-0fa6-41dc-99d4-55bdcf950191
📥 Commits

Reviewing files that changed from the base of the PR and between 2dc98c9 and 35993d9.

📒 Files selected for processing (4)
  • src/main/codex/codex-structured-item-streams.ts
  • src/main/codex/codex-structured-journal-translation-streams.test.ts
  • src/main/native-chat/agent-session-wire/agent-session-delta-coalescer.test.ts
  • src/main/native-chat/agent-session-wire/agent-session-delta-coalescer.ts

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


📝 Walkthrough

Walkthrough

The coalescer now tracks retained text length and supports an optional predicate that can skip snapshot emission. Codex uses this predicate to apply its checkpoint growth threshold. Tests cover Unicode and truncation length tracking, below-threshold checkpoints, retries, and flush behavior.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 35993

No actionable issue is identified before merge. Complete the remaining CI checks, including packaging and additional platforms.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the main change: reducing copies of Codex output between saved checkpoints.
Description check ✅ Passed The description explains the change, its purpose, testing, visual-proof status, and compatibility considerations. The maintainer audit justifies the absence of a linked issue under the template’s main…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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.

@nwparker
nwparker merged commit d9ab505 into main Oct 8, 2026
53 of 55 checks passed
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