From a224608a0ed58aa130c5781f1671067a1df488bb Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Mon, 16 Nov 2026 21:32:10 +0800 Subject: [PATCH] :zap: 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 --- frontend/src/app/main/ui/workspace/viewport/frame_grid.cljs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/viewport/frame_grid.cljs b/frontend/src/app/main/ui/workspace/viewport/frame_grid.cljs index 931fb6e4df..9f5ac07459 100644 --- a/frontend/src/app/main/ui/workspace/viewport/frame_grid.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/frame_grid.cljs @@ -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"}