Harness: the stage tracer went blind the moment FastRenderer shipped

instrument.py wrapped Renderer.render, which FastRenderer overrides - so
once the row writer became the default paint the trace showed only the
handful of frames that still fall back to prompt_toolkit, and read as a
plausible-looking session rather than an obviously broken one. Hooked at
Application._redraw instead, which is renderer-agnostic.

With it seeing again, two corrections. Leaving a screen is not slow: the
escape paint is ~10 ms and the menu repaint that follows lands ~46 ms
later as an untriggered tick, ~90 ms in all - the 520-570 ms in the tour
tables was console-quiescence overshoot. And the idle tick still
recomposes: 34 ms on the menu, 70 ms on Contacts, every 2 s, where
Contacts spends 151 render_to_ansi calls filling a ~20-row viewport.

Both go in the plan, along with the reading rule that found them: judge an
action by the rows *after* it too, since anything the menu loop does when
a screen pops is asynchronous and lands unattributed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Fable 5 committed 2026-08-09 03:07:33 -04:00
1 parent 077f8d6a1b
commit b3ba39f4bb
2 files changed
+24 -8

No files matched your search

+13 -2
View File
@@ -98,8 +98,19 @@ ssh … 'cd $HOME/MeshTerm && .venv/bin/python drive_console.py --script nav_all
where `run_instrumented.sh` is a two-line wrapper `exec .venv/bin/python instrument.py "$@"`.
It appends a CSV row per repaint to `$HOME/tmp/keytrace.csv`: handle, header, compose,
dialog, parse, pt-render, total, and the `render_to_ansi` call count. Rows tagged `~tick`
are idle repaints — what the app burns doing nothing.
dialog, parse, paint, total, and the `render_to_ansi` call count. Rows tagged `~tick` are
idle repaints — what the app burns doing nothing.
It hooks `Application._redraw`, deliberately, because MeshTerm swaps in its own
`FastRenderer` for plain frames: patching `Renderer.render` sees only the paints that fall
back to prompt_toolkit, and reports a handful of dialog repaints as if they were the whole
session. If a trace comes back suspiciously sparse, that is the first thing to check.
**Read the row *after* an action, not just the action's own row.** Leaving a screen is a
good example: the `escape` row is ~10 ms, and the menu that replaces it repaints ~46 ms
later as an untriggered `~tick` (the menu loop resumes asynchronously, so it is not
attributed to the key). Judging Esc by its own row alone understates it; judging it by
console quiescence overstates it — the truth was ~90 ms, from the sequence.
## Traps that cost real time
@@ -31,8 +31,8 @@ def _add(key, dt):
def install():
from prompt_toolkit.application import Application
from prompt_toolkit.formatted_text import ANSI
from prompt_toolkit.renderer import Renderer
from meshterm.ui.tui import frame as frame_mod
from meshterm.ui.tui import render as render_mod
@@ -144,13 +144,17 @@ def install():
ANSI.__init__ = ansi_init
# --- pt's render + the terminal write ----------------------------------------
orig_render = Renderer.render
# --- the paint, whichever renderer performs it -------------------------------
# Hooked at Application._redraw rather than Renderer.render, because MeshTerm swaps in
# its own FastRenderer for plain frames (ui/tui/fastrender.py) — patching the base
# class's method would then see only the paints that fall back to prompt_toolkit, and
# silently report a handful of dialog repaints as if they were the whole session.
orig_redraw = Application._redraw
def render(self, app, layout, is_done=False):
def redraw(self, render_as_done=False):
t = time.perf_counter()
try:
return orig_render(self, app, layout, is_done)
return orig_redraw(self, render_as_done)
finally:
try:
_log_render(time.perf_counter() - t)
@@ -160,6 +164,8 @@ def install():
with open(TRACE + ".log", "a") as fh:
fh.write(traceback.format_exc() + "\n")
Application._redraw = redraw
def _log_render(dt):
ms = lambda k: _acc.get(k, 0.0) * 1000 # noqa: E731
t_disp = _state["t_dispatch"]
@@ -184,7 +190,6 @@ def install():
_acc.clear()
_flush()
Renderer.render = render
def _flush():