mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-09 08:21:50 +00:00
Empirical work via CDP harnesses under apps/desktop/scripts/ (see
profile-typing-lag.md):
jsListeners growth (per round of 200 chars + GC):
before: +35 (verified leak — listeners stuck after 1st trigger popover use)
after: +0
Four narrow edits in src/app/chat/composer/index.tsx:
1. Drop the per-keystroke `editorRef.current.scrollHeight` read used to
decide composer expansion. Replace with `draft.length > 60` heuristic;
the existing ResizeObserver still catches edge cases. `scrollHeight`
is a forced-layout call and was firing on every char until the first
wrap.
2. Bucket measured composer height to 8px before writing
`--composer-measured-height` / `--composer-surface-measured-height`
on `documentElement`. Without this, the editor grows ~1px per char,
setProperty fires every keystroke, computed style is invalidated tree-
wide.
3. Remove the dead `$composerDraft` two-way sync. Nothing outside the
composer subscribed to that atom (verified via grep). Two useEffects
on `[draft]` were pushing draft→atom and atom→aui per keystroke for
no consumer. Also drop the per-keystroke
`reconcileComposerTerminalSelections` call; it was pruning stale
labels for `terminalContextBlocksFromDraft`, but that helper already
ignores labels not in the current submitted text, so pruning per
keystroke was just bookkeeping.
4. `refreshTrigger` fast-bails when the draft contains neither `@` nor
`/`. Previously `textBeforeCaret(editor)` ran on every input/keyup
regardless; `range.toString()` inside is O(n) over draft length.
Synthetic typing latency p50/p90/p99 is similar before vs after on a
freshly-loaded session (Blink can already handle ~30cps typing into a
contentEditable on its own); the real win is the listener leak being
gone and the global computed-style invalidations dropping ~8× when the
composer is sitting at a fixed height row.
The `Enter → stall` follow-up (see profile-typing-lag.md §"Submit /
TTFT stall") is unmeasured here — needs a throwaway session because
the harness fires a real prompt. Not blocking this commit.
38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
// quick probe — read state of the renderer
|
|
const list = await (await fetch('http://127.0.0.1:9222/json/list')).json()
|
|
const tgt = list.find(t => t.type === 'page' && t.url.startsWith('http'))
|
|
console.log('target:', tgt?.url)
|
|
if (!tgt) process.exit(1)
|
|
const ws = new WebSocket(tgt.webSocketDebuggerUrl)
|
|
let id = 0
|
|
const pending = new Map()
|
|
ws.addEventListener('message', ev => {
|
|
const m = JSON.parse(ev.data)
|
|
if (m.id != null && pending.has(m.id)) {
|
|
pending.get(m.id)(m)
|
|
pending.delete(m.id)
|
|
}
|
|
})
|
|
await new Promise(r => ws.addEventListener('open', r))
|
|
const send = (method, params = {}) =>
|
|
new Promise(r => {
|
|
const i = ++id
|
|
pending.set(i, r)
|
|
ws.send(JSON.stringify({ id: i, method, params }))
|
|
})
|
|
|
|
const r = await send('Runtime.evaluate', {
|
|
expression: `({
|
|
url: location.href,
|
|
title: document.title,
|
|
rootChildren: document.getElementById('root')?.children.length ?? 0,
|
|
rootInner: (document.getElementById('root')?.innerHTML ?? '').slice(0, 300),
|
|
hasComposer: !!document.querySelector('[data-slot="composer-rich-input"]'),
|
|
bootStage: (document.querySelector('[data-slot*="boot"]')?.getAttribute('data-slot')) ?? null,
|
|
bodyText: document.body.innerText.slice(0, 300),
|
|
errorCount: window.__errors?.length ?? 'n/a'
|
|
})`,
|
|
returnByValue: true
|
|
})
|
|
console.log('raw:', JSON.stringify(r, null, 2))
|
|
ws.close()
|