⚡ Memoize boards with grids in frame-grid* (#13075)

On a test file `mem_benchmark` with 30k boards on one page, around 11ms is
spent each time the view is panned/zoomed iterating over each board and
checking has-grid?, which after https://github.com/penpot/penpot/pull/12790 is
now slightly slower because it involves an array scan.

We don't need to compute the list of boards with grids on every step of the pan
and can memoize it, which saves 30k calls to has-grid? on each frame.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
Luke Lau 2026-11-16 21:32:10 +08:00 committed by GitHub
parent bd4af28d78
commit a224608a0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -167,8 +167,9 @@
(mf/defc frame-grid*
{::mf/wrap [mf/memo]}
[{:keys [zoom transform selected focus vbox clip-rulers] :or {clip-rulers false}}]
(let [frames (->> (mf/deref refs/workspace-frames)
(filter has-grid?))
(let [frames (mf/deref refs/workspace-frames)
frames (mf/with-memo [frames]
(into [] (filter has-grid?) frames))
transforming (when (some? transform) selected)]
[:g.grid-display {:style {:pointer-events "none"}