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
1 change: 1 addition & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## 2024-06-08 - IconifyIcon Performance Bottleneck\n**Learning:** The IconifyIcon component was doing O(N) array iteration lookups over all icon sets on every render for prefix-less icons, which is a performance bottleneck in React 19 / MUI applications.\n**Action:** Use a Map to cache iconData resolution to prevent performance-blocking lookups.
21 changes: 19 additions & 2 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,
};

// ⚑ Bolt: Cache icon resolution to avoid O(N) iteration over iconSets on every render
const iconCache = new Map<string, ReturnType<typeof getIconData>>();

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;
}
}

// Cache negative result to avoid re-searching missing icons
iconCache.set(icon, null);
return undefined;
};

const IconifyIcon = ({
Expand Down