Repository navigation
perf(sdk): a re-render leaves unchanged hotkeys alone - #1187
Conversation
|
Review (GPT 6.1 Sol, xhigh) on a163c6e: PASS, no findings.
|
Acceptance: PASSChecked How: Done means
Key-press results in the published frameCI on the head is green, including Golden journeys
Rollback answers: they match the diff. A revert leaves no schema, data or contract. Patches built with this SDK keep the faster hook until they refresh, and the release before works with them. Not run
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
a163c6e to
878dea3
Compare
…ges publish (#1241) ## What changed This adds release 36's What's new entry, written from `1acc968`. It covers everything merged since release 35's `through` (`dd0e2ec`), and sets the `patchy` release to `0.36.0` in `packages/patchy/package.json` and `CURRENT_RELEASE`. | Change | PRs | | --- | --- | | Improved: shortcuts work where you use them (keys for one part of a patch, the closest wins, text boxes keep their typing keys) | #1231 | | Improved: the shortcuts sheet shows what works where you are (Ctrl+/ and ⌘/ open it, its commands run, it opens from a patch's menu and in view on a narrow screen, keeps the look, spells keys out away from a Mac) | #1231, #1181, #1178, #1180, #1177 | | Fixed: keys pressed while a patch opens reach it | #1183 | | Fixed: pages styled with Tailwind 4 publish, and a look with the same rule saves | #1191 | | Fixed: an old copy of a patch no longer replaces newer work (**Breaking** for such a copy: it needs `patchy pull` or one `--allow-behind` publish) | #1179 | | Improved: your agent can check a publish before sending it | #1188 | | Improved: your agent hears what changed when it updates a patch | #1186, #1185 | | Fixed: your agent stops chasing false alarms (`pnpm install` exit codes, `manifest.json` bytes, the description notice, a copied dev record) | #1176, #1174, #1175 | | Behind the scenes: fuller hotkeys instructions for agents; fewer redraw costs for patches with many shortcuts | #1182, #1187 | `patchChanges` has three sentences for the agent refreshing a patch across this release: - #1231's, from its PR: text fields keep their keys, `preventDefault()`, and the sheet's Mod+/ and `.hotkey-row` buttons. - The sheet's dialog renders in `document.body`, and element-only page rules don't reach it (#1178, #1180). Its own row lists last (#1181). The hotkey label helpers take only valid literals (#1177). - Publish's `unknown_base_version` (#1179). It also rewords release 33's "Press ? to see every shortcut a patch has". That was true only for a patch that mounts the shortcuts sheet, so it now says a patch *can* list its shortcuts. The rest get no line: - #1206, #1207, #1209 and #1220 are `pnpm dev eval` tooling. - #1222 is release 35's own entry. ## Look at - **The entry**, at the top of `releases` in `packages/core/src/whatsNew.ts`, and release 33's reworded line. - **Rollback safety, from the live commit `d28fdd0` (release 35) to `1acc968`:** - #1191 is labelled `one-way`. Its Release impact: a company look published after this release with a nested `@supports` condition stays stored after a revert. Release 35 refuses any bundle carrying it, so repo publishes in that company would fail until an admin runs `patchy look restore` to an earlier revision. Pages and Tailwind 4 repos already published stay published. - #1183 is the only change to what the server serves browsers: the shell's script, under a digest-named URL. Its revert leaves nothing behind. - The hotkeys PRs change `patchy/hotkeys`, which patches bundle when they are built. Published patches keep their copy. - The CLI PRs change what a CLI writes and refuses. Release 35 reads everything they leave behind: #1176's `allowBuilds` entry, #1174's indented `manifest.json`, and the `version` recorded by an `--allow-behind` publish. **Rollback line:** If this release misbehaves, roll back to `d28fdd0` (release 35). First check that no company's look has a nested `@supports` condition, and `patchy look restore` an earlier revision where one does (#1191). ## How it was verified - **Tests.** `whatsNew.test.ts`, `WhatsNewPages.test.ts` and `schemas.test.ts` pass (22 tests), and `bun fmt` passes on the changed files. - **Facts.** The sheet's new `document.body` home and its element-rule reset were checked against `hotkeys.ts` and `hotkeySheet.ts` on main. - **Deploy state.** I pinned the live commit from `/healthz/deep`: `d28fdd0` (release 35). The Deploy run updated last succeeded, and none is unfinished. ## Release impact - [ ] **Breaking** — requires action from anyone already running this - [x] **Not breaking** — no action required Text and version numbers only. Like every release, the `0.36.0` bump tells CLIs and patch repos installed before this deploy to upgrade. - **What does a revert leave behind?** Nothing. - **Does the release before it still work with that?** Yes. Built by Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, through T3 Code. Co-authored-by: Claude Opus 5.5 <[email protected]>
What changed
useBindingsupdated every binding after every commit of the component that registers them. A whiteboard registers about 50 hotkeys from a component that re-renders on each collaborator's move. In Chromium on a fast, idle workstation, that cost p50 270 µs and p95 500 µs per commit, right at the issue's 0.5 ms bar. With the CPU throttled 2×, it was p50 1.7 ms and p95 4 ms. Now a re-render that changes nothing about the bindings leaves them alone, and each hotkey still runs its latestrun.Closes #1162
Look at
Where the time went. A CPU profile of the 50-binding component, re-rendering every few milliseconds, splits it in two:
updatetook about 60%. It re-parses every hotkey on each call (normalizeHotkey), anddetectPlatform()lower-cases the navigator's platform and user agent once per binding. That function alone was the largest self-time.permitted()took about 30%: it normalized every hotkey again during render to look for the reservedMod+Shift+K.TanStack's own equality check stops it from publishing unchanged options, but only after all of that work.
The change, in
packages/patchy/src/hotkeys.tsandhotkeyRules.ts:enabledandwhileTyping, plus the enclosingHotkeyScope. While that holds, the registrations aren't touched. When it changes, they update in place as before, so a sequence in progress isn't restarted.runandrepeatstay current without an update.permitted()remembers, per hotkey string, whether it binds the reserved chord.Numbers. Per-commit cost of one 50-binding
useHotkeyscall in headless Chromium, re-rendering on an 8 ms timer. Each case ran 3 rounds of 2,000 commits, the first 300 of each round dropped. Bundles and cases alternated round by round. The page is cross-origin isolated, soperformance.now()resolves to 5 µs. The window runs from just before the call in render to a layout effect just after it. memo reuses one binding table, as the whiteboard does withuseMemo. fresh builds a new table with new closures on every render.On an idle, fast workstation,
main's p95 sits right at the issue's 0.5 ms bar. With the CPU throttled, or other work on the machine, it is well over. With this PR, the hotkeys add about 15 µs to a commit, close to the no-hotkeys baseline in every case. Skipping the update alone, without rememberingpermitted()'s answer, left p50 at 100 µs and p95 at 175–360 µs on the loaded machine.The measured component
Callbacks stay fresh. A new browser step in the lifecycle test has a counter whose
useHotkey("I", …)closes over the count it rendered with, sorunchanges every render while nothing else does. Pressing I three times must read 1, 2, 3. With the callback reading the binding captured at registration instead, the step fails:With the change, all four hotkeys browser tests pass (
4 passed), including the existing ones for sequences, scopes, remounts mid-press, conflict warnings and the sheet.How it was verified
Locally, with CI on this PR as the judge for the full suite:
pnpm check: format, lint, typecheck and synth pass. Its offline tests failed only in suites this change doesn't touch: strayGET /requests to the CLI's local stub servers and timeouts on a heavily loaded shared machine.vitest runonhotkeys.test.ts,hotkeyRules.test.ts,hotkeySheet.test.tsandpageImports.test.ts: 39 of 39 pass.playwright test -c playwright.tier1.config.ts --project=chromium hotkeys: red then green, as above.mainand this branch's built package.pnpm verify, which the machine's load ruled out.Release impact
Internal to the patch-side SDK: the same hotkeys register with the same options, only less often.
Built by Claude Opus 5.5 (
claude-opus-5-5) in Claude Code, through T3 Code.