Skip to content

perf(codex): reduce allocations while reading app-server output - #174468

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-codex-stdio-transport-main-20260919
Oct 16, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-codex-stdio-transport-main-20260919

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Reading Codex app-server stdout allocates a buffer view and a fresh fragment array for every frame, even when its consumer finishes synchronously.

User Impact

Less temporary allocation while streaming Codex output. No wire-protocol or user-visible behavior changes; frame ordering, UTF-8 handling, EOF delivery, close cleanup, and asynchronous decode backpressure remain unchanged.

Why This Change Was Made

Reuse the reader-owned fragment array and retain the unread chunk only when asynchronous decoding actually pauses delivery. This removes work from the existing framing owner rather than adding another decoder or worker.

The profile that motivated investigation attributed app-server launch and process-inspection helpers to the transport bundle: all sampled stacks for that bundle ended in native process spawning, not JSON parsing. Current code already frames bytes without repeated concatenation and delegates large catalog responses to its existing worker. This PR makes the smaller measured allocation improvement; it does not claim to eliminate the reported transport-bundle CPU share.

Evidence

Median over five paired runs on the final source:

Traffic Main CPU, before → after (ms/MiB) Sampled allocation, before → after (MiB/MiB)
Streaming deltas 12.01 → 11.92 5.384 → 4.694 (−12.8%)
Mixed catalog/history 2.35 → 2.30 2.310 → 2.261 (−2.1%)

CPU is neutral within observed run-to-run noise; the allocation reduction is consistent across all five runs. This is a net deletion/simplification with no measured regression.

Measurement: Linux, Node 26.8.1, fake child process writing 128 MiB per run through a real stdout pipe in 16 KiB writes. Five alternating before/after runs per scenario. Streaming uses UTF-8 message deltas; mixed traffic adds 100-row catalog pages and large full-history responses. The consumer uses the production framing and envelope routing functions, parses synthetic messages, and verifies frame counts, byte totals, and content checksums. Catalog delivery returns a resolved promise to exercise pause/resume ordering; these numbers isolate framing/decoding and do not measure the production catalog worker or Gateway end to end. CPU uses process.threadCpuUsage() without allocation sampling; allocations use separate V8 heap-sampling runs including collected objects at an 8 KiB interval. The unused outbound logging import is stubbed; no inbound transport logic is replaced.

Focused proof: node scripts/run-vitest.mjs extensions/codex/src/app-server/client-message-decoder.test.ts extensions/codex/src/app-server/client-catalog-worker.test.ts --maxWorkers=1 — 27 passed, 2 files; wrapper wall time 125.41 s (compilation dominates; individual tests 4–286 ms). The initial invocation was aborted by source-snapshot verification after the final edit; the unchanged final source passed on the next invocation.

OPENCLAW_OXLINT_SKIP_PREPARE=1 node scripts/run-oxlint.mjs --tsconfig extensions/codex/tsconfig.json extensions/codex/src/app-server/client-message-frames.ts, changed-file oxfmt --check, and git diff --check passed. The initial lint invocation's broad SDK artifact preparation was stopped to respect the local compute limit; the supported skip-preparation route ran the same file-scoped lint. Independent autoreview is clean through P2.

Simplification pass: production +5/-6 lines (net -1), test delta 0. Existing behavioral coverage is reused; no new module, export, dependency, cache, configuration, or schema. No Testbox/Crabbox lease allocated. Broad build/typecheck/lint/test gates are delegated to PR CI.

@clawsweeper

clawsweeper Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review October 16, 2026 17:12
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T17:15:43.945412Z fae63d1 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete
steipete merged commit d5e1370 into main Oct 16, 2026
180 of 181 checks passed
@steipete
steipete deleted the steipete/perf-micro-codex-stdio-transport-main-20260919 branch October 16, 2026 17:24
vincentkoc added a commit that referenced this pull request Oct 16, 2026
…158510

* commit 'cff3c307ba6d0ce273abcdaf5cade848d9746d30':
  feat(decisions): preserve native catalog capabilities and accounting (#157492)
  fix(ui): avoid reactive read warnings in picker scrolling (#174436)
  refactor(test): remove unused Nextcloud fixture signing (#174470)
  refactor(browser): share managed tab eviction fixtures (#174474)
  fix(update): preserve Windows inspection path identities (#174471)
  perf: reduce large-session compaction and indexing allocations (#174433)
  perf(codex): reduce allocations while reading app-server output (#174468)
  fix(gateway): skip startup publication checks without a target (#174453)
  refactor: deslop agent harnesses, channel plugins and packages (wave-6 bundle A) (#173531)
  perf(state): reduce shared SQLite worker heap retention (#174420)
  refactor: remove routine channel callsite diagnostics (#174402)
vincentkoc added a commit that referenced this pull request Oct 16, 2026
…esafe-decision-native

* commit 'cff3c307ba6d0ce273abcdaf5cade848d9746d30':
  feat(decisions): preserve native catalog capabilities and accounting (#157492)
  fix(ui): avoid reactive read warnings in picker scrolling (#174436)
  refactor(test): remove unused Nextcloud fixture signing (#174470)
  refactor(browser): share managed tab eviction fixtures (#174474)
  fix(update): preserve Windows inspection path identities (#174471)
  perf: reduce large-session compaction and indexing allocations (#174433)
  perf(codex): reduce allocations while reading app-server output (#174468)
  fix(gateway): skip startup publication checks without a target (#174453)
  refactor: deslop agent harnesses, channel plugins and packages (wave-6 bundle A) (#173531)
  perf(state): reduce shared SQLite worker heap retention (#174420)
  refactor: remove routine channel callsite diagnostics (#174402)

# Conflicts:
#	src/agents/decision-inference.integration.test.ts
vincentkoc added a commit that referenced this pull request Oct 16, 2026
…/decision-tool-v2-proof-20261016

* commit 'cff3c307ba6d0ce273abcdaf5cade848d9746d30':
  feat(decisions): preserve native catalog capabilities and accounting (#157492)
  fix(ui): avoid reactive read warnings in picker scrolling (#174436)
  refactor(test): remove unused Nextcloud fixture signing (#174470)
  refactor(browser): share managed tab eviction fixtures (#174474)
  fix(update): preserve Windows inspection path identities (#174471)
  perf: reduce large-session compaction and indexing allocations (#174433)
  perf(codex): reduce allocations while reading app-server output (#174468)
  fix(gateway): skip startup publication checks without a target (#174453)
  refactor: deslop agent harnesses, channel plugins and packages (wave-6 bundle A) (#173531)
  perf(state): reduce shared SQLite worker heap retention (#174420)
  refactor: remove routine channel callsite diagnostics (#174402)

# Conflicts:
#	docs/plugins/sdk-overview/capabilities.md
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant