Repository navigation
perf(text): prepare long replies faster at ASCII boundaries - #163573
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 7:13 AM ET / 11:13 UTC (Revision 11). ClawSweeper reviewWhat this changesThe PR speeds long-reply preparation by skipping Unicode segmentation at safe ASCII boundaries while preserving existing chunk contents. Merge readiness✅ Ready for maintainer review Keep open: this is a useful, bounded performance improvement absent from current main and the latest release. The supplied production-entrypoint benchmark supports the claimed benefit; no actionable correctness or security finding remains. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw splits outgoing replies into chunks that fit channel limits. A shared text-boundary owner keeps Unicode characters intact for plain-text and Markdown delivery. flowchart TD
A[Outgoing reply] --> B[Plain text or Markdown chunker]
B --> C[Preferred cut and size limit]
C --> D{Safe ASCII boundary?}
D -->|Yes| E[Accept cut directly]
D -->|No| F[Unicode segmentation]
E --> G[Chunks for channel delivery]
F --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +13. Total +13 across 1 file. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep the optimization in the existing boundary owner, preserving Unicode fallback and limiting performance claims to the measured reply-preparation workloads. Do we have a high-confidence way to reproduce the issue? Not applicable to a correctness bug; the body provides reproducible before/after measurements of the production reply chunker, which this read-only review did not execute. Is this the best way to solve the issue? Yes: the shortcut stays within the existing owner and preserves segmentation for every boundary outside its narrow ASCII condition. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7340738654fc. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (10 earlier review cycles; latest 8 shown)
|
79be485 to
13c80e8
Compare
13c80e8 to
2bfa777
Compare
2bfa777 to
486e8ec
Compare
Worked by Codex.
4899bdb to
7c8e2fc
Compare
|
Independent verification of
This measures reply preparation, not model generation or network latency. Synthetic workload and shared-machine noise limit cross-runtime/general performance claims. Existing grapheme, UTF-16 boundary and auto-reply chunk suites: 125 tests passed in three files, 17.59 s runner wall. The two cancelled checks are metadata automation, not selected test shards: label and PR context and evidence, both cancelled during checkout. Their exact selected test-file lists are empty; no test replay is applicable. The current labels include Canonical production typecheck No merge of main is necessary: main has no intervening changes to the grapheme owner or chunk entrypoint since the PR merge base, and merge-tree is clean. No source edits or new push were needed, preserving the existing reviewed head and contributor credit. No live gate is needed: this is a pure-function optimization, with no Gateway behavior change beyond speed. |
|
Landed. Thanks @boeingchoco! A differential fuzz (408k comparisons, mixed Unicode) found zero mismatches, the real chunkText path produced byte-identical chunks for a 200 KB reply, and mostly-ASCII chunking went from 1.69 ms to 1.21 ms median with no Unicode-heavy regression. |
…#163573) Return the preferred chunk cut directly when both adjacent code units are ASCII (except CR LF), avoiding a full-source grapheme segmentation per cut when splitting long replies for channel delivery. Chunk contents are unchanged. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Preparing long replies for channel delivery spends avoidable time checking character boundaries between ASCII characters.
User Impact
Long replies containing ASCII boundaries take less CPU time to split before channel delivery. Existing chunk contents and Unicode handling remain unchanged; there are no configuration or migration requirements. This measures reply preparation, not model generation or network latency. Unicode-heavy inputs have no demonstrated performance benefit.
Why This Change Was Made
findGraphemeChunkEndcreates a segment view over the full source for every cut. The shortcut accepts integer boundaries between two ASCII code units, excluding CRLF. Other boundaries use the existingIntl.Segmenterpath, including the Bun surrogate workaround. Unicode grapheme rules support this boundary check.Evidence
Candidate
7c8e2fcaf497fb4f210d093580ffe0875011a8b7, updated on October 4, 2026 against upstream main6aefbb11f30aabb872e7fc379e4b97af7217903c. The final diff is one production file with 13 added lines. All earlier fixture repairs are incorporated from main. No test, dependency, schema, configuration, timeout, ignore, or CI changes remain in this PR.Measured the actual
src/auto-reply/chunk.ts:chunkTextentrypoint on Linux x64, Node 26.10.0. These measurements used basea6b9da2bdeeeb5d666fe7434972acd84451af6fd; both compiled bundles differ only ingrapheme.ts. The boundary owner and reply/Markdown callers are unchanged between that base and the refreshed base. Limit: 4,000 UTF-16 units; three warmups; nine alternating samples; median per invocation. All measured chunk arrays are identical.The 1,000,000-unit Unicode case was approximately 40% slower in this run, despite retaining segmentation. A separate fresh-process Unicode-only check with 20 warmups and nine alternating samples measured 100,000 units at 1.195 → 1.199 ms and 1,000,000 units at 221.399 → 168.896 ms, with identical output. The direction and magnitude vary between runs, so the Unicode slowdown in the full table is retained rather than treated as a stable estimate. No consistent Unicode improvement, whole-pipeline latency benefit, or cross-runtime performance gain is claimed. These are synthetic inputs; the largest cases are stress workloads.
7c8e2fcaf497fb4f210d093580ffe0875011a8b7: 134 successful jobs, 18 intentionally skipped, no failures. The PR rollup has 163 successful checks, no failures or pending checks; GitHub reports MERGEABLE / CLEAN.pnpm test src/infra/push-web.test.ts src/gateway/server-methods/sessions-mutations.owner.test.ts src/gateway/server-methods/chat.directive-tags.test.ts packages/normalization-core/src/grapheme.test.ts packages/normalization-core/src/utf16-slice.test.ts src/shared/text-chunking.test.ts packages/markdown-core/src/chunk-text.test.ts src/auto-reply/chunk.test.ts packages/markdown-core/src/render-aware-chunking.test.ts --maxWorkers=1passed all 338 tests across nine files, 73.64 s runner wall. This exercises all previously failing files and the actual reply/Markdown boundary contracts on the final head.git diff --checkpassed. Earlier core production and related package/messaging type checks passed on the same production source. Temporary fixture repairs also passed canonical Gateway test types and existing full-file assertions. Locally, full build/full suite, all core-test type graphs, live channels and Bun/browser execution were not run for this update.Earlier CI failures and upstream repairs
CI run 37188963185 tested the earlier head
79be485c2dfffa331bc85cc22ff1028945aae923and failed two test jobs; those failures also made two aggregate gate entries red.runSqliteReadOperationSyncin 8cabfb2814f.flushPendingSessionsChangedEventsbefore its durability probe in e95e11c6793. The intermittent hosted race did not reproduce deterministically; passing earlier replays alone were not treated as proof of a fix.chat.directive-tags.test.ts. Main now connects both reader paths to the existing synthetic fixture and preserves activity checks in 6aefbb11f30.Temporary fixture repairs passed the full WebChat file (132 tests), the full Gateway manifest (594 tests, 12 local skips) and independent P2 review. CI run 37194965968 succeeded on intermediate head
4899bdb7b296535a32edce22df66e580c9a6cc1b: 136 successful jobs, 17 skipped, no failures. While that run finished, the equivalent WebChat repair landed on main, causing a real merge conflict. Taking main's complete fixtures and removing the temporary repair commit resolves that conflict and returns the PR to its original optimization-only scope. The prior successful run is prior-head evidence; final-head CI remains a separate check.Reproduce the benchmark
Save the following as
bench-text-chunking.mjsoutside the checkout, then runnode /path/to/bench-text-chunking.mjsfrom the candidate checkout after installing its locked dependencies. Temporary bundles are removed by the script. The baseline source is read from the pinned Git commit.Maintainer-intent check: No overlap with Pash/Sarah changes; no commits by either author touch the changed grapheme owner on current main.