Skip to content
Closed
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 @@ -41,3 +41,7 @@
## 2025-02-15 - Replace Array.from(map.values()).map with a for...of loop
**Learning:** Using `Array.from(map.values()).map(...)` creates an unnecessary intermediate array which wastes memory allocation and garbage collection time, particularly for frequently re-rendered components handling large collections.
**Action:** Use a `for...of` loop over `map.values()` to iterate and push mapped elements directly into the final array for O(1) memory and avoiding intermediate array allocations.

## 2025-02-16 - Array reduce Performance with Absolute Bounds
**Learning:** Using unconditional `.reduce()` to find a minimum/maximum when an absolute bound (e.g. 'low' confidence) is known results in unnecessary iterations over the entire collection, hurting performance O(N).
**Action:** Replace unconditional `.reduce()` calls with a `for...of` loop and early `break` when absolute limits exist, converting the operation to O(K) where K is the index of the first absolute bound found.
25 changes: 25 additions & 0 deletions apps/desktop/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,31 @@ describe("App", () => {
expect(screen.getAllByText(/2 sections/i).length).toBeGreaterThan(0);
});

it("short-circuits confidence summary calculation when encountering low confidence", async () => {
const loadedProject = succeededResult().result;
loadedProject.sections.push({
...loadedProject.sections[0],
id: "low-confidence-section",
label: "bridge",
confidence: { level: "low", source: "model", notes: "Bridge is uncertain." }
});
loadedProject.sections.push({
...loadedProject.sections[0],
id: "high-confidence-section",
label: "outro",
confidence: { level: "high", source: "model", notes: "Outro is clear." }
});
mockLoadProject.mockResolvedValueOnce(loadedProject);
render(<App />);

fireEvent.click(screen.getByRole("button", { name: /open project/i }));

await waitFor(() => {
expect(screen.getByText(/^Low$/i)).toBeTruthy();
});
expect(screen.getAllByText(/3 sections/i).length).toBeGreaterThan(0);
});

it("selects a local audio source and starts a local-audio analysis job", async () => {
tauriInvoke
.mockResolvedValueOnce(bootstrapResponse())
Expand Down
22 changes: 14 additions & 8 deletions apps/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,21 @@ function MetricCard({
function ConfidenceMetric({ song }: { song: RehearsalSong | null }) {
const sectionCount = song?.sections.length ?? 0;
const confidenceOrder = { high: 3, medium: 2, low: 1 } as const;
const lowestConfidence = song?.sections.reduce<RehearsalSong["sections"][number]["confidence"]["level"] | null>(
(current, section) => {
if (!current || confidenceOrder[section.confidence.level] < confidenceOrder[current]) {
return section.confidence.level;

// Performance Optimization: Replaced O(N) .reduce() with for...of loop and early return
// This allows short-circuiting when the absolute lowest confidence ('low') is found.
let lowestConfidence: RehearsalSong["sections"][number]["confidence"]["level"] | null = null;
if (song?.sections) {
for (const section of song.sections) {
if (!lowestConfidence || confidenceOrder[section.confidence.level] < confidenceOrder[lowestConfidence]) {
lowestConfidence = section.confidence.level;
}
return current;
},
null
);
if (lowestConfidence === "low") {
break; // Early exit since "low" is the absolute minimum possible value
}
}
}

const confidence = lowestConfidence ? `${lowestConfidence[0].toUpperCase()}${lowestConfidence.slice(1)}` : "Ready";
const detail = sectionCount > 0 ? `${sectionCount} section${sectionCount === 1 ? "" : "s"}` : "Local analysis";

Expand Down
Loading