Skip to content

Commit bef1246

Browse files
authored
Merge pull request #310 from KxlSys/bolt-optimization-matching-page-11450142854350254193
⚡ Bolt: Memoize displayList in ProjetsTab
2 parents b6fe074 + da264aa commit bef1246

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

.jules/bolt.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
## 2024-07-10 - O(n) Single Pass Data Aggregation
2222
**Learning:** Using chained array methods (e.g. `.map().filter()`, `.flatMap()`, and repeated `.filter()` over the same large list like `profiles`) leads to redundant O(n) passes over data and allocates unnecessary intermediate arrays. This blocks the main thread longer than necessary when calculating basic statistics like `uniqueCities`, `uniqueTechs`, or total counts.
2323
**Action:** Consolidate statistical aggregations over large object arrays into a single O(n) `for` loop that updates multiple accumulators (like `Set` objects and primitive counters) in one pass, thereby improving performance and reducing memory overhead.
24-
## 2024-03-24 - React Component State and List Derivation
25-
**Learning:** In components with highly interactive state (like a button triggering a local state change), deriving and formatting large lists inside the render body without memoization causes redundant O(N) object allocations on every render.
26-
**Action:** Always wrap data derivations (like mapping a raw dataset into UI-ready objects) inside a `useMemo` hook, ensuring the dependency array only includes variables that actually alter the list structure.
24+
25+
## 2024-07-18 - Component Map Memoization Pattern
26+
**Learning:** In React components with highly interactive state (like buttons triggering local state changes such as `visibleCount`), mapping over raw datasets to create derived UI objects outside of a `useMemo` block leads to unnecessary O(N) object allocations and garbage collection on every render.
27+
**Action:** When a component derives lists from props or state for rendering, wrap the mapping or filtering logic inside `useMemo` to cache the result, recalculating only when the underlying data changes, thereby freeing up the main thread from redundant object allocations.

src/pages/matching-page.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,15 +508,17 @@ function ProjetsTab({
508508
}
509509
}, [user, interested]);
510510

511-
// ⚡ Bolt: Memoize displayList to prevent O(N) object allocations on every render
512-
// (e.g. when 'interested' state changes after clicking the "Je suis intéressé" button).
511+
// ⚡ Bolt: Memoize the mapping logic to prevent O(N) object allocations on every render
512+
// This avoids redundant work when local interactive states (like visibleCount or interested) change.
513+
// Impact: Reduces main-thread blocking during re-renders by caching derived datasets.
513514
const displayList: { project: Project; score?: number; reasons?: string[] }[] = useMemo(() => {
514515
return profile && projectMatches.length > 0
515516
? projectMatches.map((m) => ({ project: m.project, score: m.score, reasons: m.reasons }))
516517
: projects.map((p) => ({ project: p }));
517518
}, [profile, projectMatches, projects]);
518519

519-
const visible = displayList.slice(0, visibleCount);
520+
// ⚡ Bolt: Memoize slicing to prevent re-instantiating the visible array on unrelated renders.
521+
const visible = useMemo(() => displayList.slice(0, visibleCount), [displayList, visibleCount]);
520522

521523
if (isLoading) {
522524
return (

0 commit comments

Comments
 (0)