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 <help@stably.ai>
This commit is contained in:
Jinwoo-H
2026-07-03 02:07:21 -04:00
co-authored by Orca
parent 64b6f7abea
commit 71c89da9bb
2 changed files with 27 additions and 2 deletions
+16 -1
View File
@@ -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
@@ -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)