Repository navigation
improve(telegram): speed up formatting long replies - #150213
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 September 16, 2026, 2:07 PM ET / 18:07 UTC. ClawSweeper reviewWhat this changesThe PR reduces CPU work when formatting long Telegram replies by decoding and appending whole text segments while preserving HTML output and chunk boundaries. Merge readiness✅ Ready for maintainer review Keep open: this is a focused, useful optimization that remains absent from current main and the latest release. Source review found no actionable correctness defect; the protected maintainer submission should proceed through normal review. Priority: P2 Review scores
Verification
How this fits togetherTelegram’s formatter converts assistant Markdown into size-limited HTML messages. Its visible-text projection detects transcript-like role headers while excluding code, so outgoing chunks retain appropriate assistant identification. flowchart LR
A[Assistant Markdown] --> B[Telegram HTML rendering]
B --> C[Decode visible text segments]
C --> D[Exclude code from header detection]
D --> E[Protect transcript headers]
E --> F[Measure and split chunks]
F --> G[Telegram delivery]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -22. Total -22 across 1 file. View PR surface stats
Review metrics
Technical reviewBest possible solution: Retain one shared entity decoder and the existing transcript-protection logic while removing repeated per-character projection work. Do we have a high-confidence way to reproduce the issue? Not applicable as a functional bug reproduction: this is a performance optimization. Current source confirms the repeated projection work, and the body reports comparative measurements; this review did not rerun them. Is this the best way to solve the issue? Yes. Reusing the existing decoder for each segment is a narrow simplification that preserves text and offsets without introducing caches, settings, or another formatting owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ca38979d2128. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
Closes #150211
What Problem This Solves
Formatting long Telegram replies spends CPU rebuilding visible text one character and entity at a time during repeated chunk-size probes.
User Impact
Long replies format faster with identical HTML and chunk boundaries. No configuration or migration is required.
Why This Change Was Made
Decode each text segment once with the existing entity decoder, then append the segment as a whole. Code exclusions and transcript-header protection keep the same visible text and UTF-16 offsets. This removes the per-character loop without adding a cache.
Evidence
The actual
markdownToTelegramChunkscaller was measured in 12 fresh processes: three alternating baseline/candidate pairs on each of Node 24.19.0 and 26.8.2. All 13,056 timed calls and every adverse result were retained. Median paired wall-time changes:The short case is noisy (two of three Node 24 pairs were slower); no short-message improvement or network-latency claim. Windows CPU counters were too coarse for short cases. Inputs were synthetic, approximately 4–9.5K visible characters for the long cases, with a 4,000-character HTML cap. Parsing and formatting were timed together; imports, output comparisons, and warmups were outside the timed region.
format.test.tsandformat.wrap-md.test.ts.