From 122bcdda5466ee368fcfc53fb76579a06ec4ef04 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 4 May 2026 11:18:57 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20cache=20IconifyIcon=20lookups?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a `Map` cache inside `client/src/components/base/IconifyIcon.tsx` to memoize the result of `getIconData()` lookup logic across renders. This stops linear checking across multiple static icon bundles. Co-authored-by: sshahriazz <34005640+sshahriazz@users.noreply.github.com> --- .jules/bolt.md | 3 +++ client/src/components/base/IconifyIcon.tsx | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..10bf102 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2025-02-12 - IconifyIcon Lookups Uncached +**Learning:** `client/src/components/base/IconifyIcon.tsx` resolves icons statically from multiple imported `@iconify-json` bundles but performs a linear lookup with `getIconData()` on every render without caching. +**Action:** Add a simple `Map` cache inside `IconifyIcon.tsx` to memoize the result of `getIconData()` across renders. diff --git a/client/src/components/base/IconifyIcon.tsx b/client/src/components/base/IconifyIcon.tsx index b48f0dc..dc7976f 100644 --- a/client/src/components/base/IconifyIcon.tsx +++ b/client/src/components/base/IconifyIcon.tsx @@ -33,18 +33,33 @@ const iconSets: Record = { "mdi-light": mdiLightIcons, }; +import { IconifyIcon as IconifyIconType } from "@iconify/react"; + +const iconCache = new Map(); + const iconData = (icon: string) => { + if (iconCache.has(icon)) return iconCache.get(icon); + const [prefix, name] = icon.includes(":") ? icon.split(":") : ["", icon]; if (prefix && iconSets[prefix]) { const data = getIconData(iconSets[prefix], name); - if (data) return data; + if (data) { + iconCache.set(icon, data); + return data; + } } for (const [_, icons] of Object.entries(iconSets)) { const data = getIconData(icons, name); - if (data) return data; + if (data) { + iconCache.set(icon, data); + return data; + } } + + iconCache.set(icon, undefined); + return undefined; }; const IconifyIcon = ({