Skip to content

perf: frame-limit Pen and Pencil interactions#125

Merged
dompm merged 5 commits into
codex/interaction-performancefrom
codex/interaction-pen-pencil
Jul 16, 2026
Merged

perf: frame-limit Pen and Pencil interactions#125
dompm merged 5 commits into
codex/interaction-performancefrom
codex/interaction-pen-pencil

Conversation

@dompm

@dompm dompm commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • share one Pen resolver between hover and click
  • frame-limit Pen hover publication
  • capture Pencil samples in a mutable controller and isolate its overlay

Why

This reduces repeated pointer-path allocation and computation while preserving exact click-time snapping and every raw Pencil sample.

Stack

Depends on #123 (codex/interaction-performance).

Verification

  • interaction test suite passes
  • production build succeeds
  • no new TypeScript errors beyond the documented baseline

This is a draft pending performance review and browser regression testing.

@dompm dompm left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shared resolver and Pencil buffer are useful improvements, but the Pen half does not yet meet the isolation checkpoint.

  • [P1] Keep Pen preview state out of ResultPanel. The scheduled hover callback still invokes five panel-level setters. React batches them, but ResultPanel still rerenders and rebuilds its piece element map and surrounding UI once per hover frame. The plan calls for one Pen snapshot consumed by a focused overlay/status subscriber so stable panel work is skipped.
  • [P2] Refresh the stationary-Shift resolver. The global keyboard effect depends only on activeTool, so it captures the resolver/index/project geometry from the render in which Pen was activated. If geometry or crop changes while the tool stays Pen (for example after committing a polygon), Shift press/release at a stationary cursor resolves against stale data. Keep the latest resolver in a ref or otherwise refresh the handler without losing keyboard behavior.
  • [P2] Cancel queued hover work when clearing Pen UI. Pointer leave and tool changes clear state but do not cancel the pending animation-frame task. A previously scheduled task can run afterward and restore a stale hover/guides, including when Pen is selected again. Cancel the scheduler at every preview-cancellation boundary and add a scheduler race test.

Pencil does retain every raw tuple and removes the growing immutable copy from the raw-event path. Its drawing snapshot still copies the cumulative flat buffer once per frame, so describe the win as “no cumulative copy per raw event,” not no cumulative copies at all.

@dompm
dompm force-pushed the codex/interaction-pen-pencil branch from 0e3a6ce to 7ddd236 Compare July 13, 2026 17:33
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 13, 2026

Copy link
Copy Markdown

Deploying vitrai with  Cloudflare Pages  Cloudflare Pages

Latest commit: 27f999f
Status: ✅  Deploy successful!
Preview URL: https://199e6238.vitrai.pages.dev
Branch Preview URL: https://codex-interaction-pen-pencil.vitrai.pages.dev

View logs

@dompm dompm left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local Pen preview state is isolated, and the stale-resolver/cancellation fixes look correct. One high-frequency path still defeats that isolation:

  • [P1] Keep Pen status out of App state. Every preview update runs onStatusChange, which is setPenStatus in App. That produces a new status object every frame, rerenders App, and invokes the non-memoized ResultPanel again. In other words, the overlay host's local state no longer directly rerenders the panel, but its status effect immediately causes the same broad render through the parent. Put the Pen status in the same stable external snapshot/controller and let only a focused status-bar subscriber render it (or provide an equivalently isolated route). Add a count test using the real status callback boundary, not only the preview host.

The unused isShiftDown panel state can also be removed; it is no longer read and is still part of the documented TypeScript baseline.

@dompm
dompm force-pushed the codex/interaction-pen-pencil branch from 8d9481f to e06506d Compare July 16, 2026 16:19
@dompm
dompm force-pushed the codex/interaction-performance branch from 1d00b43 to 30bc4d5 Compare July 16, 2026 16:19
* perf: frame-limit viewport gesture publication

* perf: move viewport gestures into focused store subscribers

* perf: narrow viewport subscriptions around stable canvas children

* perf: keep glass pieces idle during pan

* perf: index Pen snapping with reference parity (#127)

* perf: index pen snapping with reference parity

* perf: cache shift-alignment snap queries

* fix: preserve project order in length snapping

* test: randomize equal-length snap parity

* fix: preserve current snapping behavior on indexed path
@dompm
dompm marked this pull request as ready for review July 16, 2026 16:49
@dompm
dompm merged commit 4d7eda5 into codex/interaction-performance Jul 16, 2026
2 checks passed
@dompm
dompm deleted the codex/interaction-pen-pencil branch July 16, 2026 16:49
dompm added a commit that referenced this pull request Jul 16, 2026
* perf: add interaction fixtures and behavior baselines

* perf: cache piece geometry and memoize canvas pieces

* perf: isolate stable and interaction canvas layers

* perf: preview piece transforms outside project state

* fix: address interaction foundation review feedback

* fix: preserve debug mask composition backdrop

* perf: frame-limit Pen and Pencil interactions (#125)

* perf: frame-limit pen and pencil interaction controllers

* fix: refresh and cancel scheduled pen previews

* perf: isolate pen preview from result panel

* perf: isolate pen status from app state

* perf: frame-limit viewport gesture publication (#126)

* perf: frame-limit viewport gesture publication

* perf: move viewport gestures into focused store subscribers

* perf: narrow viewport subscriptions around stable canvas children

* perf: keep glass pieces idle during pan

* perf: index Pen snapping with reference parity (#127)

* perf: index pen snapping with reference parity

* perf: cache shift-alignment snap queries

* fix: preserve project order in length snapping

* test: randomize equal-length snap parity

* fix: preserve current snapping behavior on indexed path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant