mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-14 04:02:26 +00:00
chore(tui): /clean recent perf work — KISS/DRY pass
24 files, -319 LoC. Behaviour preserved, 369/369 tests green. - hermes-ink caches: shared lruEvict helper for the four parallel LRU caches (stringWidth, wrapText, sliceAnsi, lineWidth); touch-on-read stays inlined per cache; tightened output.ts skip-slice fast path. - wheelAccel: trimmed provenance header, collapsed env parsing, ternary dispatch in computeWheelStep. - perfPane: folded ensureLogDir into once-flag, spread-with-overrides for fastPath/phases instead of full rebuilds. - env: extracted truthy() (used 4×). - virtualHeights: collapsed user/diff/slash height bumps; trail+todos estimate. - useInputHandlers: scrollIdleTimer cleanup on unmount, ?? undefined shorthand. - useMainApp: dropped dead liveTailVisible IIFE and liveProgress indirection. - appLayout, markdown, messageLine, entry: vertical rhythm, dropped narration comments, inlined one-shot vars. - fix: empty catch blocks → /* best-effort */ for no-empty lint.
This commit is contained in:
parent
527ac351b4
commit
b1c49d5e73
32 changed files with 259 additions and 547 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { type AnsiCode, ansiCodesToString, reduceAnsiCodes, tokenize, undoAnsiCodes } from '@alcalzone/ansi-tokenize'
|
||||
|
||||
import { lruEvict } from '../ink/lru.js'
|
||||
import { stringWidth } from '../ink/stringWidth.js'
|
||||
|
||||
function isEndCode(code: AnsiCode): boolean {
|
||||
|
|
@ -19,7 +20,9 @@ const sliceCache = new Map<string, string>()
|
|||
const SLICE_CACHE_LIMIT = 4096
|
||||
|
||||
export default function sliceAnsi(str: string, start: number, end?: number): string {
|
||||
if (!str) return ''
|
||||
if (!str) {
|
||||
return ''
|
||||
}
|
||||
|
||||
// Hot-path: only cache when end is defined (the Output.get() use-case).
|
||||
if (end !== undefined) {
|
||||
|
|
@ -29,6 +32,7 @@ export default function sliceAnsi(str: string, start: number, end?: number): str
|
|||
if (cached !== undefined) {
|
||||
sliceCache.delete(key)
|
||||
sliceCache.set(key, cached)
|
||||
|
||||
return cached
|
||||
}
|
||||
|
||||
|
|
@ -39,6 +43,7 @@ export default function sliceAnsi(str: string, start: number, end?: number): str
|
|||
}
|
||||
|
||||
sliceCache.set(key, result)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
@ -50,16 +55,7 @@ export function sliceCacheSize(): number {
|
|||
}
|
||||
|
||||
export function evictSliceCache(keepRatio = 0): void {
|
||||
if (keepRatio <= 0) {
|
||||
sliceCache.clear()
|
||||
return
|
||||
}
|
||||
|
||||
const target = Math.floor(sliceCache.size * keepRatio)
|
||||
|
||||
while (sliceCache.size > target) {
|
||||
sliceCache.delete(sliceCache.keys().next().value!)
|
||||
}
|
||||
lruEvict(sliceCache, keepRatio)
|
||||
}
|
||||
|
||||
function computeSlice(str: string, start: number, end?: number): string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue