Skip to content

Commit 6c78dee

Browse files
perf(studio): a long project's timeline stops redrawing every clip when its elements change (#6773)
1 parent c922591 commit 6c78dee

3 files changed

Lines changed: 35 additions & 10 deletions

File tree

‎packages/studio/src/hooks/useRenderClipContent.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,35 @@ describe("useRenderClipContent", () => {
105105
return unwrapPeakMarks(content);
106106
}
107107

108+
it("keeps one renderer while the timeline's elements change, so no clip redraws for it", () => {
109+
const projectIdRef = { current: "my-project" };
110+
const compIdToSrc = new Map<string, string>();
111+
const renderers: unknown[] = [];
112+
function Harness() {
113+
renderers.push(
114+
useRenderClipContent({
115+
projectIdRef,
116+
compIdToSrc,
117+
activePreviewUrl: null,
118+
effectiveTimelineDuration: 12,
119+
}),
120+
);
121+
return null;
122+
}
123+
const host = document.createElement("div");
124+
document.body.append(host);
125+
const root = createRoot(host);
126+
act(() => root.render(React.createElement(Harness)));
127+
act(() =>
128+
usePlayerStore.setState({
129+
elements: [{ id: "a", tag: "audio", start: 0, duration: 1, track: 1 }],
130+
}),
131+
);
132+
act(() => root.unmount());
133+
134+
expect(new Set(renderers).size).toBe(1);
135+
});
136+
108137
function renderRaw(el: TimelineElement): ReactNode {
109138
const host = document.createElement("div");
110139
document.body.append(host);

‎packages/studio/src/hooks/useRenderClipContent.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ function renderAudioClip(
6868
sessionEpoch: number,
6969
labelColor: string,
7070
context: TimelineClipRenderContext,
71-
elements: readonly TimelineElement[],
7271
labelInset?: number,
7372
): ReactNode {
7473
const audioUrl = resolveMediaPreviewUrl(
@@ -96,7 +95,7 @@ function renderAudioClip(
9695
sessionEpoch,
9796
priority: context.priority,
9897
labelInset,
99-
...audioPillFlags(el, elements),
98+
...audioPillFlags(el),
10099
});
101100
return createElement(
102101
ClipPeakMarks,
@@ -136,7 +135,6 @@ export function useRenderClipContent({
136135
const effectiveMode = effectiveThumbnailMode(thumbnailMode);
137136
const sessionEpoch = usePlayerStore((s) => s.timelineSessionEpoch);
138137
const thumbnailRevisions = usePlayerStore((s) => s.thumbnailRevisions);
139-
const elements = usePlayerStore((s) => s.elements);
140138
return useCallback(
141139
// Pre-existing clip-content dispatcher; reduced by extracting renderAudioClip.
142140
// fallow-ignore-next-line complexity
@@ -151,7 +149,7 @@ export function useRenderClipContent({
151149
// Thumbnail generation disabled (perf) -> plain clip bars. Audio still shows
152150
// its waveform (cheap, not a frame thumbnail). Toggle: timeline toolbar.
153151
const waveform = (labelInset?: number) =>
154-
renderAudioClip(el, pid, sessionEpoch, style.label, context, elements, labelInset);
152+
renderAudioClip(el, pid, sessionEpoch, style.label, context, labelInset);
155153
if (effectiveMode === "hidden") {
156154
return rendersWaveform(el) ? waveform() : withSoundStrip(el, null, waveform);
157155
}
@@ -190,7 +188,7 @@ export function useRenderClipContent({
190188
// activePreviewUrl thumbnail branch; audio rows need waveform data, not a
191189
// captured frame from the currently drilled composition preview.
192190
if (rendersWaveform(el)) {
193-
return renderAudioClip(el, pid, sessionEpoch, style.label, context, elements);
191+
return renderAudioClip(el, pid, sessionEpoch, style.label, context);
194192
}
195193

196194
if (el.text) return createElement(TextClipContent, { text: el.text });
@@ -282,7 +280,6 @@ export function useRenderClipContent({
282280
effectiveMode,
283281
sessionEpoch,
284282
thumbnailRevisions,
285-
elements,
286283
],
287284
);
288285
}

‎packages/studio/src/player/components/audioClipLink.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ export function sharesLinkGroup(
3434
return isLinked(a) && a.link === b.link && sameCompositionScope(a, b);
3535
}
3636

37-
export function audioPillFlags(
38-
audio: Pick<TimelineElement, "hidden" | "audioGroupHidden">,
39-
_elements?: readonly unknown[],
40-
): { muted: boolean } {
37+
export function audioPillFlags(audio: Pick<TimelineElement, "hidden" | "audioGroupHidden">): {
38+
muted: boolean;
39+
} {
4140
return { muted: audio.hidden === true || audio.audioGroupHidden === true };
4241
}
4342

0 commit comments

Comments
 (0)