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
Expand Up @@ -5,3 +5,6 @@
## 2025-03-09 - Replace .map() with point updates for React state arrays
**Learning:** For updating single items in small React state arrays (e.g., layout configurations or task lists), using `array.map()` introduces significant performance overhead by iterating through the entire array and calling the callback for every element. This causes unnecessary processing.
**Action:** Prefer "point updates" using `findIndex` and array spreading over `array.map()`. This minimizes object allocations and improves fluidity, especially on lower-power devices.
## 2026-05-20 - Consolidating multiple array iterations in React useMemo hooks
**Learning:** When deriving multiple unique sets of data from a single source array (e.g., categories and profiles from a shortcuts list), chaining array methods like `.map()`, `.flatMap()`, and creating separate `useMemo` hooks leads to redundant iterations and intermediate array allocations. In large datasets, this overhead scales linearly per derived array.
**Action:** Consolidate these calculations into a single `useMemo` hook using a single `for...of` loop to populate multiple `Set`s simultaneously. This pattern minimizes iterations, reduces memory pressure, and is significantly faster than multiple chained methods.
21 changes: 16 additions & 5 deletions components/CategoryFilterWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ import { UsersIcon } from '@heroicons/react/24/outline';
export const CategoryFilterWidget: React.FC = () => {
const { shortcuts, filterCategory, setFilterCategory, filterProfile, setFilterProfile } = useGTab();

const activeCategories = useMemo(() => {
return ['All', ...new Set(shortcuts.map(s => s.category))];
}, [shortcuts]);
const { activeCategories, uniqueProfiles } = useMemo(() => {
const catSet = new Set<string>();
const profSet = new Set<string>();

for (const s of shortcuts) {
if (s.category) catSet.add(s.category);
if (s.profiles) {
for (const p of s.profiles) {
if (p.name) profSet.add(p.name);
}
}
}

const uniqueProfiles = useMemo(() => {
return Array.from(new Set(shortcuts.flatMap(s => s.profiles?.map(p => p.name) || []))).sort();
return {
activeCategories: ['All', ...catSet],
uniqueProfiles: Array.from(profSet).sort()
};
}, [shortcuts]);

return (
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Loading