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.
22 lines
928 B
JavaScript
22 lines
928 B
JavaScript
#!/usr/bin/env node
|
|
// Launch the desktop renderer with HMR disabled so the React Fast Refresh
|
|
// preamble path is skipped. This sidesteps a current Vite 8 / plugin-react 6
|
|
// bug where the preamble script is not injected into index.html → renderer
|
|
// throws "$RefreshReg$ is not defined" on every TSX module → React tree
|
|
// never mounts.
|
|
//
|
|
// We're not trying to use HMR while profiling typing lag anyway. Hermes desktop
|
|
// boots, you type, profiler measures. HMR off is fine.
|
|
//
|
|
// Usage: node apps/desktop/scripts/dev-no-hmr.mjs
|
|
// (then in another shell, run electron --remote-debugging-port=9222 .)
|
|
|
|
import { createServer } from 'vite'
|
|
|
|
const server = await createServer({
|
|
configFile: new URL('../vite.config.ts', import.meta.url).pathname,
|
|
root: new URL('../', import.meta.url).pathname,
|
|
server: { hmr: false, host: '127.0.0.1', port: 5174, strictPort: true }
|
|
})
|
|
await server.listen()
|
|
server.printUrls()
|