diff --git a/.claude/skills/profile-picocalc/SKILL.md b/.claude/skills/profile-picocalc/SKILL.md index f2095c2..16a1a6f 100644 --- a/.claude/skills/profile-picocalc/SKILL.md +++ b/.claude/skills/profile-picocalc/SKILL.md @@ -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 diff --git a/.claude/skills/profile-picocalc/scripts/instrument.py b/.claude/skills/profile-picocalc/scripts/instrument.py index bdd1050..62665c9 100644 --- a/.claude/skills/profile-picocalc/scripts/instrument.py +++ b/.claude/skills/profile-picocalc/scripts/instrument.py @@ -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():