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
5 changes: 5 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@

**Learning:** In Next.js/React applications, when grouping items (like schedules or talks) into a `Map` where the values are arrays, using the array spread operator `[...existing, item]` inside a loop (like `forEach` or `map`) causes amortized O(N^2) memory allocations and unnecessary Garbage Collection overhead.
**Action:** Always use `.push()` on the existing array reference if the data structure permits local mutation. For strict ESLint configurations enforcing `no-restricted-syntax`, extract the existing array, push to it, and handle the fallback elegantly (`if (!existing) { map.set(key, [item]); } else { existing.push(item); }`).

## 2024-05-18 - Replacing Object.entries().find() with Direct Property Access

**Learning:** When retrieving a value from an object based on a matching key, using `Object.entries(obj).find(([key]) => key === target)?.[1]` introduces unnecessary array allocations and linear search overhead. This is particularly harmful inside frequently executed loops or filter functions.
**Action:** Replace `Object.entries(obj).find()` loops with direct `obj[target]` property access (O(1) time complexity) whenever possible. Cast the key using `as keyof typeof obj` if TypeScript enforces strict key constraints.
4 changes: 2 additions & 2 deletions lib/shared/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function getEditionNavigation(year: string): Promise<EditionNavigat

const hasSchedule = schedule.length > 0;

const editionCfp = Object.entries(cfpData).find(([y]) => y === year)?.[1];
const editionCfp = cfpData[year];
const hasCfp = editionCfp ? editionCfp.some((track) => track.members && track.members.length > 0) : false;

const hasDiversity = config.diversity.sponsors.length > 0;
Expand All @@ -39,7 +39,7 @@ export async function getEditionNavigation(year: string): Promise<EditionNavigat
return links
.filter((link) => {
if (!link.condition) return true;
const conditionValue = Object.entries(conditions).find(([key]) => key === link.condition)?.[1];
const conditionValue = conditions[link.condition as NavCondition];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The type assertion as NavCondition is redundant here. Since link.condition is typed as NavCondition | undefined in the NavItem interface, and we have already guarded against undefined on line 41, TypeScript automatically narrows its type to NavCondition. Removing the redundant cast improves readability and type safety.

Suggested change
const conditionValue = conditions[link.condition as NavCondition];
const conditionValue = conditions[link.condition];

return !!conditionValue;
})
.map((link) => {
Expand Down
Loading