Skip to content

[feat] canvas: Show project structure before loading node media when opening or switching projects #446

Open

Description

@Redivesue

Goal and scope

Switching to a project with existing creative content currently waits for node content hydration before the workspace becomes interactive. Show nodes, connections, layout and the saved viewport first, then load node content independently so one slow asset does not block the entire workspace.

Related work:

This proposal covers opening, switching to and returning to existing projects. It preserves authoritative project data, reference relationships, result adoption and editing permissions.

User flow and key rules

  • Flush necessary edits to the current project. After the destination snapshot and editing session are confirmed, display its structure and allow navigation and layout operations whose persistence requirements are satisfied.
  • Load node content independently, prioritize visible nodes and bound background concurrency. Provide per-node loading, failure and retry feedback.
  • Never save unloaded text, media or editor data as empty values. Preserve actual content through autosave, undo/redo, copying and reopening. Late reads must not overwrite user edits, newer object versions or another project's state.
  • Cancelling presentation reads must not implicitly cancel Agent runs or accepted generation jobs, or change references or adoption. Cancelling one consumer must not break a shared media read needed by others.
  • Hidden or unloaded content retains its business identity and dependencies. Editing, playback, generation and export require their actual inputs to be ready; a placeholder alone is not readiness.
  • Preserve browser and desktop authentication, original media, HEIF browser previews, editable document structures, locks and version checks. New loading/error/retry feedback must support both Chinese and English.

Implementation impact and evidence

Evidence baseline: upstream commit fc2ff9f7. The excerpts below omit unrelated code. The traced entry point is selecting an existing project in the project picker, not downloading/importing a bundled example.

1. The workspace remains non-interactive until the destination document returns

The picker callback calls switchDocument(() => openWorkspaceProject(project)).

switchDocument performs these steps in order:

setSwitching(true);
// ... await persistCurrentDocument(...)
const next = await read();
installDocument(next, fit);
// ... finally:
setSwitching(false);

The workspace root uses inert={!ready || switching}. Destination installation and interaction therefore wait for read(), not just the structural snapshot. Unchanged saves can complete without a business write; save queue time needs separate measurement.

2. Reference verification can delay the structural response

POST /open-canvas computes reference states before returning:

snapshot = projects.open(project_id, str(x_opendirector_session))
return {'snapshot': snapshot, 'edges': canvas.reference_edges(project_id, snapshot)}

The path is reference_edges → check_asset → reference_available → open_media. On a verification-cache miss, open_media calls stream_identity:

while chunk := stream.read(CHUNK_BYTES):
    digest.update(chunk)

This cost is conditional: verified files are cached and the reference query deduplicates checks. Measure the cold-cache cost separately; do not remove integrity validation to improve latency.

3. After receiving the structure, hydration still waits for complete media bodies

CreationProjection.open():

await this.client.open();           // snapshot and reference states received
this.baseline = await this.read();  // content hydration is still required

read() builds nodes through await Promise.all(snapshot.canvasItems.map(...)); each media node awaits this.client.mediaUrl(asset.id).

mediaUrl → blob waits for the complete response body before creating an object URL:

const response = await fetch(
  `/api${creationPath(this.id)}/assets/${assetId}/${representation}`,
  { headers, signal },
);
// ... status check
return response.blob();
// ... mediaUrl creates URL.createObjectURL(blob) after this resolves

Node reads may run concurrently, but the document waits for the slowest branch. This path does not explicitly request a Range. The content endpoint supports Range but defaults to the whole file without it. Streaming the response on the server does not remove the client's full-body wait.

4. Hidden nodes and unopened editor resources also participate

Hidden nodes are separated only after hydration:

document.hiddenNodes = document.nodes.filter(node => !visible.has(node.id));
document.nodes = document.nodes.filter(node => visible.has(node.id));

Node hydration also awaits associated editor documents. Timeline hydration awaits imported assets and clip resources, widening the first-display dependency set.

Complete waiting chain

Select existing project → disable interaction → await saves/session queue
→ open-canvas: read snapshot + verify reference assets
→ hydrate all canvas items: text / complete media bodies / editor resources
→ wait for slowest branch → separate hidden nodes
→ install destination document → restore interaction → browser presentation

Verification and limits: A local function-level probe invoked the actual CreationProjection.read(), mediaUrl() and blob() with a mocked fetch whose response body was controlled. In both a visible-slow-video case and a hidden-slow-video case, the fast asset finished but the document remained pending until the slow response body ended. Both media requests had no Range header. This establishes the blocking dependency, not real-user latency: the probe did not run browser rendering, a real backend or video decoding. No measured user-case timings or speedup factor are claimed. The awaited resources are those requested by document hydration, not every historical media version.

The existing canvas_switch.mjs measures two empty canvases; it cannot substitute for a media-heavy switching benchmark.

Acceptance criteria

  • With one media response deliberately delayed, the destination structure is visible and basic canvas operations are available before that response completes; other nodes can finish independently.
  • Hidden-node media and unopened-editor media do not block initial structure readiness. A failed node read is isolated and retryable.
  • Edits, autosaves, undo/redo, copying and reopening during partial loading preserve authoritative content. Rapid switching, node removal/replacement and background completion cannot install stale content or affect another project.
  • Integrity checks, editing leases, locks, references, adoption and Agent/job lifecycle semantics remain intact. Browser and desktop preview, editing, playback and export paths have representative coverage.
  • Record a real, media-heavy two-canvas baseline and an equivalent post-optimization comparison. Both A and B must contain substantial real media and editing content. Record each project's node/edge counts, media counts and sizes, editor-document scale, hardware, app version, build and runtime. Separate initial/cold opens from repeated switches and document cache conditions. After two warm-up round trips, measure at least 10 switches in each direction (A→B and B→A), retaining individual samples and reporting median and nearest-rank P90. Start at the target-project click and record first feedback, structural interactivity and visible-content readiness separately, with a recording or performance trace. Keep projects, environment and operation order comparable. Use this as one comparison dataset alongside the controlled-delay probe; empty-canvas results are insufficient.
  • Attribute save/queue, structural response, media transfer and rendering time separately where observable. Do not claim readiness merely because a title or loading placeholder appears.
  • New loading/failure/retry copy is available in Chinese and English; run npm run check:i18n and inspect the flow in both languages.

Activity

  1. added
    area:canvasCanvas, nodes and direct manipulation
    area:i18nLocalisation and bilingual UI
    area:performancePerformance and responsiveness / 性能与响应速度
    on Nov 22, 2026
  2. Redivesue commented on Nov 22, 2026

    @Redivesue
    Author

    Hi, I'd like to work on this issue and submit a PR.

    I've reviewed the relevant loading path. My plan is to first record a switching baseline using two real, media-heavy canvases, then implement progressive loading so the canvas structure becomes usable before all node media is ready. I'll preserve the save, reference, versioning and job-lifecycle rules, and include regression coverage and comparable before/after measurements in the PR.

    Could you assign this issue to me? I'm happy to discuss the approach with the maintainers before implementation.

    Thanks!

  3. Redivesue commented on Nov 23, 2026

    @Redivesue
    Author

    Pre-optimization baseline at fc2ff9f7

    cc @FayeSpica for visibility.

    I measured real media-heavy canvas switching in both the browser and a packaged desktop build. First feedback is within budget, but the canvas stays unusable for about 5–8 s at the median, against the 500 ms budget in docs/development/ui-performance.md. No code has been changed yet.

    Switching results

    Each direction has 10 measured switches after 2 warm-up round trips. Values are median / nearest-rank P90 in ms, with timers starting at the target-project click.

    Metric A→C browser A→C desktop C→A browser C→A desktop
    First feedback 19 / 20 18 / 30 17 / 19 18 / 21
    Structure interactive 6123 / 6995 5788 / 7137 5390 / 6365 8283 / 10115
    Visible content ready 6551 / 7306 6218 / 7565 6556 / 6881 9756 / 11911
    Save and queue before open 11 / 11 12 / 243 9 / 10 12 / 15
    open-canvas request 1468 / 1922 1662 / 2943 224 / 729 668 / 1866
    Media wait after open 4527 / 5230 3727 / 4171 4829 / 5548 6836 / 8238

    Cold opens after a server or app restart (n=3, structure interactive, median / P90 in ms):

    Canvas Browser Desktop
    A 6478 / 6802 8103 / 8463
    C 2311 / 3066 3391 / 3447

    What the data shows

    • Media hydration is the main blocker. The workspace unlocks only after the media reads finish. Save and queue time is usually about 10 ms.
    • Hidden nodes add avoidable reads. Each A→C switch reads 70 media assets (990 MiB), and 20 of them (322 MiB) belong only to hidden nodes. Each C→A switch reads 132 (679 MiB), and 38 of them (244 MiB) are hidden-only.
    • A↔B cannot currently switch continuously in the browser. A→B reached structure in about 14 s, then B→A failed with net::ERR_FAILED and stayed on B. A separate fetch().blob() test with no app code began failing at about 1.94 GiB held. I have not yet determined whether the limit comes from memory or disk.
    • Project integrity held. The A and C project heads were unchanged after both complete runs.

    Test canvases

    Canvas Nodes (visible / hidden) Rendered edges Media Size Timeline clips Editor documents
    A, image-heavy 180 (133 / 47) 46 129 images, 8 videos 689 MiB 48 4 timeline, 6 layers, 1 subject
    B, video-heavy 89 (64 / 25) not recorded 36 videos plus audio 2.1 GiB 63 not recorded
    C, mixed 116 (87 / 29) 56 46 images, 14 videos, 10 audio 990 MiB 57 20 layers, 3 timeline, 2 media edit

    Media was derived with FFmpeg from real footage, audio and stills, so these are realistic stress fixtures rather than user projects.

    Environment

    • Common: OpenDirector 0.1.5, MacBook Air M2 (Mac14,2), 16 GB RAM, macOS 26.5.1, 1500×1000, en-US.
    • Browser: production build via opendirector serve, headless Chrome 157.0.8103.79, Python 3.13.9, Node 24.15.0 for the harness.
    • Desktop: packaged, ad-hoc signed Electron 45.3.3 (Chromium 156.0.8078.100), Python 3.12.13, built with Node 24.22.1, driven over CDP.

    Limitations and open questions

    • Browser and desktop differ in headless mode, Chromium version and network timing source, so differences between them are directional. The before/after comparison will be made within each runtime.
    • The OS page cache was not flushed. I recorded performance traces for each direction but have not analyzed them, and I have no screen recording yet.
    • Desktop A↔B has not been measured.
    • Not yet explained: slower desktop C→A media loading, warm switches to C being slower than cold opens, and occasional slow open-canvas calls. The 128-entry integrity-verification cache is one candidate for the last item, but this is unproven.
    • /assistant/draft returned 409 during switching (5 times in the browser run, 8 in the desktop run). I will check that this cannot lose a draft.

    Next

    I will design progressive loading around these results: show the authoritative structure first, keep hidden and off-screen media from blocking, isolate failures per node, and never save unloaded content as empty. After implementation, I will rerun the same benchmark and post the comparison with the PR.

  4. Redivesue commented on Nov 23, 2026

    @Redivesue
    Author

    Attribution and fix experiments at fc2ff9f7

    cc @FayeSpica for visibility.

    Following the baseline above, I traced where the switch time goes and tested the likely backend fixes. Most media read time is spent queueing for the global catalog lock. Removing that contention cuts time to an interactive canvas by 54–70%, but still misses the 500 ms budget, so I plan to make two-stage loading the main line of this work.

    These experiments used temporary process-local probes on isolated benchmark data in the browser runtime. No repository code has changed, and the A and C project heads were unchanged after every run.

    Where the time goes

    Share of media request time, unmodified runs Result
    Waiting for the global catalog lock 72–82%
    Reloading project history while holding the lock 5–20%
    Whole-file integrity hashing 2–7%
    Response transfer after the file is opened 4–8%
    • Each media read reloads project history under the lock. CreationAssets.open_media calls _load when no snapshot is supplied, and _load walks the commit chain. This costs about 23 ms per asset on A and 8 ms on C, and those sections run serially.
    • /reference-catalog repeats that work for every asset. It already holds a snapshot but does not pass it to reference_available. On A, one catalog request made about 140 reads and took about 8.8 s, so it could continue into the next switch.
    • The lock holder differs by direction. In a run that recorded every holder, the previous project's catalog held the lock for 3.3 s of the 5.8 s A→C window (56%). A's own media reads held it for 3.5 s of the 4.9 s C→A window (73%).
    • The 128-entry verification cache is not the main cause. Disabling eviction removed repeated hashing but saved only about 0.4–0.7 s of media read time, which is close to the run-to-run variation.

    Single and combined fix experiments

    Each direction has 10 measured switches after 2 warm-up round trips. Values are median / nearest-rank P90 in ms.

    Experiment A→C structure A→C visible content C→A structure C→A visible content
    Control 6609 / 7084 7200 / 7631 5495 / 6197 6005 / 6551
    Catalog fix only 3724 / 4003 4164 / 4337 4829 / 4947 5350 / 6722
    Media read fix only 5559 / 6050 6260 / 6619 2005 / 2424 3240 / 4628
    Both 3013 / 3502 3334 / 4248 1621 / 1864 2794 / 3744

    With both fixes, cold-open structure time also improved from 6494 to 2933 ms on A and from 2450 to 1792 ms on C (median, n=3).

    The experiment reused the head record to measure the possible gain. It is not a production fix, because it skips per-read history-chain revalidation. The real media-read change must preserve integrity checks across rollback, external file changes, project rename and multi-window writes.

    Why two-stage loading is the main line

    Even with both backend fixes, the workspace still waits for every media read. Separating structure from media removes that dependency. The table below is an estimate, not a measured prototype: before-open + open-canvas + 200 ms skeleton render, calculated per sample.

    Time to an interactive skeleton Today (measured) Two-stage only (estimate) Two-stage + both backend fixes (estimate)
    A→C, median / P90 6.6 / 7.1 s ~2.0 / 2.8 s ~1.4 / 1.9 s
    C→A, median / P90 5.5 / 6.2 s ~0.4 / 0.8 s ~0.36 / 0.36 s

    A→C would remain above budget because open-canvas itself takes about 1.2–1.8 s in that direction, so I will attribute that request separately.

    Planned final form

    Stage 1: authoritative structure

    • Build the canvas from the open-canvas snapshot without waiting for media, then show node skeletons with their real layout, titles, types and connections.
    • Keep pan, zoom, selection and layout available while media loads.
    • Keep loading state and media URLs out of the document, undo history and save baseline. Saving will rely on asset identity, so an unloaded node can never be saved as empty or treated as changed material.

    Stage 2: independent node content

    • Each node loads and renders its own content with explicit loading, ready and failed states, bilingual copy and per-node retry.
    • Use bounded, prioritized concurrency: visible nodes first, then nearby nodes. Hidden nodes and unopened editors load on demand.
    • Use lightweight previews where the canvas does not need the original, and keep originals for editing, playback and export.
    • Cancelling a presentation read must not cancel Agent runs, jobs or a media read shared by another consumer.

    Backend support

    • Reuse the existing snapshot in /reference-catalog.
    • Reduce repeated history loading in media reads without weakening integrity checks.

    Concurrency alone will not solve this. The browser already reached 4–5 concurrent media requests, but they queued behind the same lock. The limit should therefore be tuned after the lock work and must leave room for save, open and event requests.

    Limitations

    • Desktop has not been instrumented for this attribution, so these gains are not yet confirmed there.
    • The skeleton numbers are estimates until a prototype is measured.
    • Viewport-first loading will save less at fit-all zoom. In the measured warm switches, 52 media items on C and 94 on A were in view, while cold opens at the saved viewport had 1–5. Hidden-only reads remain avoidable in both cases (20 of 70 reads on A→C and 38 of 132 on C→A).
    • A↔B still needs to be rerun after loading no longer holds every media file as a Blob.

    After implementation, I will rerun the same benchmark in each runtime and post the before/after comparison with the PR.

  5. Redivesue commented on Nov 23, 2026

    @Redivesue
    Author

    Correction and B-canvas baseline at fc2ff9f7

    Correction: my earlier baseline said A↔B could not switch continuously in the browser. That failure reproduces only in Playwright's default off-the-record context. With a persistent browser profile, and in the packaged desktop app, A↔B and C↔B both complete every measured switch.

    In an off-the-record control run, the first A→B switch produced 86 failed media reads (net::ERR_FAILED) and visible content was not ready within 120 s. I have not confirmed the internal Chromium limit, so I am reporting only the difference between the two profile types.

    Pre-change switching results

    Each direction has 10 measured switches after 2 warm-up round trips. Values are median / nearest-rank P90 in ms. Project heads were unchanged after every run.

    Direction Browser structure Browser visible content Desktop structure Desktop visible content
    A→B 9733 / 11305 9905 / 11482 6841 / 10419 7112 / 10632
    B→A 5806 / 7734 7365 / 8970 9462 / 12422 11197 / 16097
    C→B 16314 / 18585 16629 / 18915 5711 / 6295 6170 / 6628
    B→C 8911 / 13466 10022 / 14265 5303 / 6382 6268 / 7319
    A→C 7630 / 8155 8267 / 8764 5788 / 7137 6218 / 7565
    C→A 5816 / 6486 7118 / 8207 8283 / 10115 9756 / 11911
    • Browser values use a persistent temporary profile, so they replace the earlier off-the-record A↔C numbers for before/after comparison.
    • Desktop A↔C comes from the earlier complete desktop baseline. The other desktop rows are new.
    • Each switch to B reads 51 media items (2094 MiB), including 14 items (809 MiB) used only by hidden nodes.
    • Cold opens of B reached structure in 7252 / 13943 ms in the browser and 3682 / 4343 ms on desktop (n=3).

    Still unexplained

    • Browser C→B is much slower than desktop C→B.
    • Desktop open-canvas occasionally reaches 4–5 s at P90.
    • Desktop runs log net::ERR_FAILED for /subscribe, and /assistant/draft still returns occasional 409s.

    Delivery plan

    I plan to deliver this in one PR with two commits, so each stage can be measured against this baseline:

    1. Structure first: show an interactive node skeleton from the authoritative snapshot, without saving unloaded media as empty content.
    2. Independent node loading: load node media with bounded, prioritized concurrency, per-node failure handling and retry.

    The implementation will extend the existing media read, projection and preview paths. Thumbnail switching and a new video streaming path are out of scope for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:canvasCanvas, nodes and direct manipulationarea:i18nLocalisation and bilingual UIarea:performancePerformance and responsiveness / 性能与响应速度

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions