From 71c89da9bb90177ad60d9aeb0412e27084a6bd4e Mon Sep 17 00:00:00 2001 From: Jinwoo-H Date: Fri, 3 Jul 2026 02:07:21 -0400 Subject: [PATCH] Pre-filter daemon OSC/mouse scanners for introducer-free chunks Skips the scan-tail copy and full-chunk walks when a chunk cannot contain an OSC or private-mode sequence (single native includes() checks), with split-sequence correctness preserved via explicit tail retention. Strictly positive micro-optimization on the daemon per-chunk path; 641 daemon tests green (1 pre-existing WSL failure unrelated). Co-authored-by: Orca --- src/main/daemon/terminal-mouse-mode-mirror.ts | 17 ++++++++++++++++- .../daemon/terminal-osc-cwd-title-scanner.ts | 12 +++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/daemon/terminal-mouse-mode-mirror.ts b/src/main/daemon/terminal-mouse-mode-mirror.ts index b54e12344..8f8b284f7 100644 --- a/src/main/daemon/terminal-mouse-mode-mirror.ts +++ b/src/main/daemon/terminal-mouse-mode-mirror.ts @@ -31,7 +31,22 @@ export class TerminalMouseModeMirror { } scan(data: string): void { - const input = this.scanTail + data + // Why the pre-filter: this runs on the daemon's per-chunk hot path for + // every session; a flood chunk with no private-mode/reset introducer + // must not pay the regex pass (measured share of a 2.2x ingest + // regression — findings log 2026-07-03). Split sequences stay correct: + // an introducer split across chunks either left a non-empty scanTail + // (previous partial) or ends this chunk, which extractScanTail retains. + if ( + this.scanTail.length === 0 && + !data.includes('\x1b[?') && + !data.includes('\x1bc') && + !data.includes('\x9b') + ) { + this.scanTail = this.extractScanTail(data) + return + } + const input = this.scanTail.length === 0 ? data : this.scanTail + data this.scanTail = this.extractScanTail(input) // oxlint-disable-next-line no-control-regex -- terminal escape sequences require control chars const privateModeRe = /\x1bc|\x1b\[\?([0-9;]+)([hl])|\x9b\?([0-9;]+)([hl])/g diff --git a/src/main/daemon/terminal-osc-cwd-title-scanner.ts b/src/main/daemon/terminal-osc-cwd-title-scanner.ts index 6d1261a5a..44cfcadf9 100644 --- a/src/main/daemon/terminal-osc-cwd-title-scanner.ts +++ b/src/main/daemon/terminal-osc-cwd-title-scanner.ts @@ -14,7 +14,17 @@ export class TerminalOscCwdTitleScanner { lastTitle: string | null = null scan(data: string): void { - const input = this.scanTail + data + // Why the pre-filter: this runs on the daemon's per-chunk hot path; flood + // chunks with no OSC introducer must not pay the title/URI walks + // (measured share of a 2.2x ingest regression — findings log 2026-07-03). + // Correctness across splits: an OSC intro spanning chunks either left a + // non-empty scanTail or this chunk ends with a bare ESC, which + // extractOscScanTail retains for the next call. + if (this.scanTail.length === 0 && !data.includes('\x1b]')) { + this.scanTail = data.endsWith('\x1b') ? extractOscScanTail(data, OSC_SCAN_TAIL_LIMIT) : '' + return + } + const input = this.scanTail.length === 0 ? data : this.scanTail + data this.scanTail = extractOscScanTail(input, OSC_SCAN_TAIL_LIMIT) scanOsc7Uris(input, (uri) => { const parsed = parseFileUriPath(uri)