Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -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<string, any>`) for `iconData` resolution to make icon object lookups O(1) on subsequent renders, avoiding redundant iterations across icon sets.
27 changes: 22 additions & 5 deletions client/src/components/base/IconifyIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,35 @@ const iconSets: Record<string, IconifyJSON> = {
"mdi-light": mdiLightIcons,
};

const iconCache = new Map<string, any>();

// ⚑ 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 = ({
Expand Down