Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@
## 2026-06-13 - Memoize SongStructure timeline
**Learning:** The SongStructure timeline component renders multiple DOM nodes for sections and re-rendered unnecessarily when the active role state changed in the parent Workspace.
**Action:** Apply React.memo to static presentational components that receive stable props (like sections) but are siblings to highly interactive state (like role filtering).

## 2025-02-13 - O(1) activeRoleDetails Lookup Optimization
**Learning:** Recomputing active role details by looping through sections and roles on every render/selection causes repeated O(totalRoles) scans.
**Action:** Use a memoized Map cache mapping role ID to the full RehearsalRole object to allow O(1) lookups.
35 changes: 16 additions & 19 deletions apps/desktop/src/features/workspace/Workspace.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useMemo, memo } from "react";
import type { ProjectBootstrapSummary, RehearsalSong } from "@bandscope/shared-types";
import type { ProjectBootstrapSummary, RehearsalSong, RehearsalRole } from "@bandscope/shared-types";
import { RoleSwitcher } from "./RoleSwitcher";
import { SectionRoadmap } from "./SectionRoadmap";
import { GrooveMap } from "./GrooveMap";
Expand Down Expand Up @@ -93,30 +93,27 @@ export function Workspace({ song, sourceBootstrap = null, onSongUpdate }: Worksp
const t = useMemo(() => createTranslator(detectPreferredLocale()), []);

// Extract all unique roles from the song's sections
const allRoles = useMemo(() => {
const roleMap = new Map<string, string>();
const roleMap = useMemo(() => {
const map = new Map<string, RehearsalRole>();
song.sections.forEach(section => {
section.roles.forEach(role => {
if (!roleMap.has(role.id)) {
roleMap.set(role.id, role.name);
if (!map.has(role.id)) {
map.set(role.id, role);
}
});
});
return Array.from(roleMap.entries()).map(([id, name]) => ({ id, name }));
return map;
}, [song]);
const activeRoleDetails = useMemo(
() => {
for (const section of song.sections) {
for (const role of section.roles) {
if (role.id === activeRole) {
return role;
}
}
}
return undefined;
},
[activeRole, song]
);

const allRoles = useMemo(() => {
return Array.from(roleMap.values()).map(role => ({ id: role.id, name: role.name }));
}, [roleMap]);

// Performance: use the cached roleMap so activeRoleDetails does not rescan sections and roles on every render.
const activeRoleDetails = useMemo(() => {
if (!activeRole) return undefined;
return roleMap.get(activeRole);
}, [activeRole, roleMap]);
const canTranscribeBass = activeRoleDetails?.name.toLowerCase().includes("bass") ?? false;

/** Documented. */
Expand Down
Loading