diff --git a/.jules/bolt.md b/.jules/bolt.md index e69de29..f563a15 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2025-05-23 - Removed Dead O(N*M) Loop in Render Cycle +**Learning:** React render loops are critical paths. Calling a function that performs nested iterations (like finding a topic for a segment) inside `array.map()` for every item creates a multiplicative performance cost (O(N*M)). If the result is unused, it's pure waste. +**Action:** Always verify if the return value of a calculation inside a render loop is actually used. If not, delete it. diff --git a/components/transcript-viewer.tsx b/components/transcript-viewer.tsx index 59ba877..ee9a95c 100644 --- a/components/transcript-viewer.tsx +++ b/components/transcript-viewer.tsx @@ -340,20 +340,6 @@ export function TranscriptViewer({ } }, [handleUserScroll]); - const getSegmentTopic = (segment: TranscriptSegment): { topic: Topic; index: number } | null => { - for (let i = 0; i < topics.length; i++) { - const topic = topics[i]; - const hasSegment = topic.segments.some( - (topicSeg) => segment.start >= topicSeg.start && segment.start < topicSeg.end - ); - if (hasSegment) { - return { topic, index: i }; - } - } - return null; - }; - - const getHighlightedText = (segment: TranscriptSegment, segmentIndex: number): { highlightedParts: Array<{ text: string; highlighted: boolean; isCitation?: boolean; isSearchMatch?: boolean; isCurrentSearchMatch?: boolean }> } | null => { // Priority: Search > Citation/Topic @@ -826,7 +812,6 @@ export function TranscriptViewer({ return transcript.map((segment, index) => { const highlightedText = getHighlightedText(segment, index); const isCurrent = index === currentSegmentIndex; - getSegmentTopic(segment); const hasHighlight = highlightedText !== null; const translation = translationsCache.get(index);