Skip to content

Commit aa22718

Browse files
committed
perf(studio): the layer walk skips clips the runtime hid, so scrubbing a long film stays smooth
The off-canvas indicators (always mounted) and the Layers panel rebuild their layer list every 100 ms while a scrub mutates the preview, and each rebuild read the computed style of every element of every scene, on screen or not. The runtime already hides everything inside a clip its visibility pass hid, so those subtrees hold no layer: the walk now skips a clip marked data-hf-clip-hidden with an inline visibility of hidden. The marker constant moves to studio-preview-mark so the runtime and Studio share one owner.
1 parent 9652a63 commit aa22718

4 files changed

Lines changed: 47 additions & 4 deletions

File tree

‎packages/core/src/runtime/clipReveal.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/** The visibility pass's mark on a timed clip it hides; the runtime's rules hide the clip's contents by it. */
2-
export const CLIP_HIDDEN_ATTR = "data-hf-clip-hidden";
1+
import { CLIP_HIDDEN_ATTR } from "../studioPreviewMark";
2+
3+
export { CLIP_HIDDEN_ATTR };
34

45
type ShaderWindow = Window & {
56
HyperShader?: unknown;

‎packages/core/src/studioPreviewMark.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const STUDIO_PREVIEW_LAZY_ATTR = "data-hf-preview-lazy";
55
export const STUDIO_PREVIEW_ERRORS = "__hfPreviewErrors";
66
export const PREVIEW_RASTER_ATTR = "data-hf-preview-raster";
77
export const RUNTIME_STAMPED_ATTR = "data-hf-autostamped";
8+
export const CLIP_HIDDEN_ATTR = "data-hf-clip-hidden";
89
export const STUDIO_PREVIEW_FAR_SCENE_ATTR = "data-hf-far-scene";
910
export const STUDIO_PREVIEW_PARKED_SCENE_ATTR = "data-hf-parked-scene";
1011
export const PREVIEW_ONLY_ATTRS = [
@@ -16,6 +17,9 @@ export const PREVIEW_ONLY_ATTRS = [
1617
RUNTIME_STAMPED_ATTR,
1718
] as const;
1819

20+
export const isClipHiddenByRuntime = (el: HTMLElement) =>
21+
el.hasAttribute(CLIP_HIDDEN_ATTR) && el.style.visibility === "hidden";
22+
1923
export function applyAuthoredTiming(
2024
el: Element,
2125
attrs: ReadonlyArray<readonly [name: string, value: string]>,

‎packages/studio/src/components/editor/domEditingLayers.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,41 @@ describe("domEditSelectionToFacts hasAudio", () => {
380380
expect((await factsFor(`<div id="d1"></div>`)).hasAudio).toBe(false);
381381
});
382382
});
383+
384+
describe("collectDomEditLayerItems and clips the runtime hid", () => {
385+
afterEach(() => {
386+
document.body.innerHTML = "";
387+
document.head.innerHTML = "";
388+
});
389+
390+
// As the runtime marks and styles a clip outside the playhead, with its rule that hides the clip's contents.
391+
function filmWithHiddenScene(hiddenStyle: string): HTMLElement {
392+
document.head.innerHTML = `<style>[data-hf-clip-hidden][data-hf-clip-hidden] * { visibility: hidden !important; }</style>`;
393+
const cells = (prefix: string, n: number) =>
394+
Array.from({ length: n }, (_, i) => `<div id="${prefix}-${i}"></div>`).join("");
395+
document.body.innerHTML =
396+
`<div data-composition-id="main">` +
397+
`<div id="now" data-start="0" data-duration="5">${cells("now", 3)}</div>` +
398+
`<div id="later" data-start="5" data-duration="5" data-hf-clip-hidden style="${hiddenStyle}">${cells("later", 50)}</div>` +
399+
`</div>`;
400+
return document.querySelector<HTMLElement>("[data-composition-id]")!;
401+
}
402+
403+
it("lists what is on screen without reading the style of anything inside a hidden clip", () => {
404+
const root = filmWithHiddenScene("visibility: hidden");
405+
const read = vi.spyOn(window, "getComputedStyle");
406+
const ids = collectDomEditLayerItems(root, opts).map((item) => item.id);
407+
const insideHidden = read.mock.calls.filter(([el]) =>
408+
document.getElementById("later")!.contains(el),
409+
);
410+
expect(ids).toEqual(["now", "now-0", "now-1", "now-2"]);
411+
expect(insideHidden).toHaveLength(0);
412+
});
413+
414+
// Older shader builds reveal a clip through its inline style alone, leaving the mark on.
415+
it("still lists a marked clip whose inline style shows it", () => {
416+
const root = filmWithHiddenScene("visibility: visible");
417+
const ids = collectDomEditLayerItems(root, opts).map((item) => item.id);
418+
expect(ids).toContain("later");
419+
});
420+
});

‎packages/studio/src/components/editor/domEditingLayers.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PREVIEW_ONLY_ATTRS } from "@hyperframes/core/studio-preview-mark";
1+
import { isClipHiddenByRuntime, PREVIEW_ONLY_ATTRS } from "@hyperframes/core/studio-preview-mark";
22
import { knownSourceAnswer, probeSourceElement, type ProbeTarget } from "./probeSourceElement";
33
import { isAudibleVideoNode } from "../../player/lib/timelineElementHelpers";
44
import type { PatchOperation } from "../../utils/sourcePatcher";
@@ -454,7 +454,7 @@ export function collectDomEditLayerItems(
454454
const items: DomEditLayerItem[] = [];
455455
// fallow-ignore-next-line complexity
456456
const visit = (el: HTMLElement, depth: number) => {
457-
if (items.length >= maxItems) return;
457+
if (items.length >= maxItems || isClipHiddenByRuntime(el)) return;
458458

459459
const entry = readDomEditLayerWalkEntry(el, options.activeCompositionPath, cache);
460460
if (entry) {

0 commit comments

Comments
 (0)