From 807a84832b31cc4901fa4f7145bc2d399b22f7c8 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 18 May 2026 10:55:23 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20Cache=20icon=20lookups=20to=20prevent=20O(n)=20iteration=20a?= =?UTF-8?q?cross=20icon=20sets=20on=20every=20render?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: sshahriazz <34005640+sshahriazz@users.noreply.github.com> --- .jules/bolt.md | 3 +++ client/src/components/base/IconifyIcon.tsx | 27 ++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..a38096b --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-24 - [Global Caching for IconifyIcon Lookups] +**Learning:** Prefix-less icon lookups in `IconifyIcon.tsx` iterate over multiple large icon sets on every render. Because the component is used heavily (192 times in the project), this linear lookup becomes a rendering bottleneck. +**Action:** Implement a simple global memoization cache (`Map`) for `iconData` resolution to make icon object lookups O(1) on subsequent renders, avoiding redundant iterations across icon sets. diff --git a/client/src/components/base/IconifyIcon.tsx b/client/src/components/base/IconifyIcon.tsx index b48f0dc..88c820d 100644 --- a/client/src/components/base/IconifyIcon.tsx +++ b/client/src/components/base/IconifyIcon.tsx @@ -33,18 +33,35 @@ const iconSets: Record = { "mdi-light": mdiLightIcons, }; +const iconCache = new Map(); + +// ⚡ Bolt: Cache icon lookups to prevent O(n) iteration across icon sets on every render const iconData = (icon: string) => { + if (iconCache.has(icon)) { + return iconCache.get(icon); + } + const [prefix, name] = icon.includes(":") ? icon.split(":") : ["", icon]; + let result; if (prefix && iconSets[prefix]) { - const data = getIconData(iconSets[prefix], name); - if (data) return data; + result = getIconData(iconSets[prefix], name); + } + + if (!result) { + for (const [_, icons] of Object.entries(iconSets)) { + const data = getIconData(icons, name); + if (data) { + result = data; + break; + } + } } - for (const [_, icons] of Object.entries(iconSets)) { - const data = getIconData(icons, name); - if (data) return data; + if (result) { + iconCache.set(icon, result); } + return result; }; const IconifyIcon = ({