From 5166b8d5ea584566d54ba180c5a2b9ccdf0211be Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Wed, 18 Nov 2026 22:17:44 +0800 Subject: [PATCH] :zap: Avoid iterating over every object in frame-titles* (#13089) * :zap: Avoid iterating over every object in frame-titles* Similarly to #13075, frame-titles* used to iterate over every object to work out the frames at the root that need titles. For files with lots of objects this can be slow, but we can just get the root frames by looking at the root object's children. We need to remove non-main-component instances to copy the behaviour of `get-frame-ids :skip-copies? true`. This also now causes the title to be drawn on a child frame whenever it's focused. AI-assisted-by: claude-opus-5-5 * :bug: Don't show frame title on focused frames Restores the existing behaviour when focused --- .../main/ui/workspace/viewport/widgets.cljs | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/viewport/widgets.cljs b/frontend/src/app/main/ui/workspace/viewport/widgets.cljs index 2c5374ced8..766f4987cd 100644 --- a/frontend/src/app/main/ui/workspace/viewport/widgets.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/widgets.cljs @@ -9,6 +9,7 @@ (:require [app.common.data :as d] [app.common.data.macros :as dm] + [app.common.files.helpers :as cfh] [app.common.geom.point :as gpt] [app.common.types.component :as ctk] [app.common.types.container :as ctn] @@ -262,34 +263,39 @@ [{:keys [objects base-objects zoom selected focus is-show-artboard-names on-frame-enter on-frame-leave on-frame-select]}] (let [selected (or selected #{}) - frame-ids (mf/with-memo [base-objects] - (vec (ctt/get-frames-ids base-objects {:skip-copies? true :ignore-index? true}))) - shapes (into [] (keep (d/getf objects)) frame-ids) - shapes (if (dbg/enabled? :shape-titles) - (into (set shapes) - (map (d/getf objects)) - selected) - shapes) + show-id? (dbg/enabled? :shape-titles) + root-frames (into [] + (comp (keep (d/getf objects)) + (filter cfh/frame-shape?) + (filter #(= uuid/zero (:parent-id %))) + (remove #(and (ctk/instance-head? %) + (not (ctk/main-instance? %))))) + (dm/get-in objects [uuid/zero :shapes])) + shapes (if show-id? + (into [] + (comp (keep (d/getf objects)) + (filter (fn [{:keys [id]}] + (and (not= id uuid/zero) + (or (empty? focus) (contains? focus id)))))) + (into (set (ctt/get-frames-ids base-objects {:skip-copies? true :ignore-index? true})) + selected)) + root-frames) edition (mf/deref refs/selected-edition) grid-edition? (ctl/grid-layout? objects edition)] [:g.frame-titles.blurrable - (for [{:keys [id parent-id] :as shape} shapes] - (when (and - (not= id uuid/zero) - (or (dbg/enabled? :shape-titles) (= parent-id uuid/zero)) - (or (empty? focus) (contains? focus id))) - [:> frame-title* {:key (dm/str "frame-title-" id) - :frame shape - :zoom zoom - :is-selected (contains? selected id) - :is-show-artboard-names is-show-artboard-names - :is-show-id (dbg/enabled? :shape-titles) - :is-grid-edition (and (= id edition) grid-edition?) - :on-frame-enter on-frame-enter - :on-frame-leave on-frame-leave - :on-frame-select on-frame-select}]))])) + (for [{:keys [id] :as shape} shapes] + [:> frame-title* {:key (dm/str "frame-title-" id) + :frame shape + :zoom zoom + :is-selected (contains? selected id) + :is-show-artboard-names is-show-artboard-names + :is-show-id show-id? + :is-grid-edition (and (= id edition) grid-edition?) + :on-frame-enter on-frame-enter + :on-frame-leave on-frame-leave + :on-frame-select on-frame-select}])])) (mf/defc frame-flow* [{:keys [flow frame is-selected zoom on-frame-enter on-frame-leave on-frame-select]}]