perf: pre-compile regex patterns and optimize hot-path string operations

- error-classifier: pre-compile default retry pattern regex
- think-mode/detector: combine multilingual patterns into single regex
- parser: skip redundant toLowerCase on pre-lowered keywords
- edit-operations: use fast arraysEqual instead of JSON comparison
- hash-computation: optimize streaming line extraction with index tracking
This commit is contained in:
YeonGyu-Kim
2026-03-18 14:19:23 +09:00
parent 90aa3a306c
commit c5c7ba4eed
5 changed files with 27 additions and 12 deletions
+11 -3
View File
@@ -11,6 +11,14 @@ import {
} from "./edit-operation-primitives"
import { validateLineRefs } from "./validation"
function arraysEqual(a: string[], b: string[]): boolean {
if (a.length !== b.length) return false
for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) return false
}
return true
}
export interface HashlineApplyReport {
content: string
noopEdits: number
@@ -51,7 +59,7 @@ export function applyHashlineEditsWithReport(content: string, edits: HashlineEdi
const next = edit.end
? applyReplaceLines(lines, edit.pos, edit.end, edit.lines, { skipValidation: true })
: applySetLine(lines, edit.pos, edit.lines, { skipValidation: true })
if (next.join("\n") === lines.join("\n")) {
if (arraysEqual(next, lines)) {
noopEdits += 1
break
}
@@ -62,7 +70,7 @@ export function applyHashlineEditsWithReport(content: string, edits: HashlineEdi
const next = edit.pos
? applyInsertAfter(lines, edit.pos, edit.lines, { skipValidation: true })
: applyAppend(lines, edit.lines)
if (next.join("\n") === lines.join("\n")) {
if (arraysEqual(next, lines)) {
noopEdits += 1
break
}
@@ -73,7 +81,7 @@ export function applyHashlineEditsWithReport(content: string, edits: HashlineEdi
const next = edit.pos
? applyInsertBefore(lines, edit.pos, edit.lines, { skipValidation: true })
: applyPrepend(lines, edit.lines)
if (next.join("\n") === lines.join("\n")) {
if (arraysEqual(next, lines)) {
noopEdits += 1
break
}
+5 -3
View File
@@ -86,15 +86,17 @@ export async function* streamHashLinesFromUtf8(
pending += text
const chunksToYield: string[] = []
let lastIdx = 0
while (true) {
const idx = pending.indexOf("\n")
const idx = pending.indexOf("\n", lastIdx)
if (idx === -1) break
const line = pending.slice(0, idx)
pending = pending.slice(idx + 1)
const line = pending.slice(lastIdx, idx)
lastIdx = idx + 1
endedWithNewline = true
chunksToYield.push(...pushLine(line))
}
pending = pending.slice(lastIdx)
if (pending.length > 0) endedWithNewline = false
return chunksToYield
}