Skip to content

perf(ui): lay out graphs in a worker, so Expand all never freezes the page - #1991

Queued
kvlonge wants to merge 15 commits into
mainfrom
feat/layout-worker
Queued

kvlonge wants to merge 15 commits into
mainfrom
feat/layout-worker

Conversation

@kvlonge

@kvlonge kvlonge commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Why

Expand all on a large project whose folders all wait on each other froze the page for seconds. Every graph was laid out on the page's thread, so clicks, scrolling and live updates waited for it.

Changes

  • Graph layouts run in a layout worker. GraphFlow sends it geometry and a LayoutRequest; card data stays on the page.
  • A newer draw ends a running layout and its worker, so a second click gets its answer and a stale layout never lands.
  • While a layout runs, the drawing before it stays in sight and can't be clicked. New cards are drawn hidden while Svelte Flow measures them. "Laying out…" shows after 300 ms.
  • A failed layout or worker shows the existing "Couldn't lay out this graph" error; Reset view starts a fresh worker.
  • The Lineage page draws through GraphFlow.redraw instead of setting cards at the origin.
  • Node icons moved to node-icons.ts, so the worker bundle holds no Svelte components. Dagre now ships only in the worker.
  • Head budgets rise by the worker's module links (+6 graph and Plan, +8 10K, +3 Checks), still measured + 4; Expand all's is 143.

DuckShop: no edge case. This changes where the UI lays out, not a project shape.

Verification

  • Expand-all work budget on a mock of the stress project (594 cards), page thread:
    • Calls 54,531,580 → 9,527,709. Layout and dagre calls 44,617,569 → 0 (budget 0).
    • Restyles 4,361 → 6,374 and relayouts 39,451 → 41,467, from hiding then showing new cards. Budgets about 1% above measured.
  • New vitest counts the worker's work on the same graph: 44,748,304 calls, budget about 1% above.
  • Real-server lineage-fit-folders.spec.ts (3,456 models, worker answers delayed 2 s): the old drawing stays in sight; Collapse all during Expand all lands and the expand never does; Expand all draws all 593 cards; no page script holds dagre.
  • graph-errors.spec.ts injects a failing layout and a failing worker; both show the error and Reset recovers.
  • Mocked layout suite, budgets and vitest pass.

A folder that didn't fit inside an opened member of a group's graph stayed
asked for, so it opened by itself once room appeared and a click on it did
nothing. Lineage, run lineage and member graphs now settle what is asked
for, and the toolbar note, through one folder-graph step.
A folder whose contents wait in a loop with what else is drawn now stays
closed at every level, its waits drawn both ways, as the top level
already did. A person opens what they want. The loop-opening cascade,
the 'opened to show order' label and the closed-by-a-person sets that
only existed to stop it are removed.
Opening a folder kept the clicked card's corner where it was, so a box
wider or taller than the room left ran off the canvas. The view now pans
at the same zoom to show the whole box, or zooms out to fit it when it
can't fit at that zoom.
Laying out a large graph ran on the main thread, so expanding every folder
of a big project froze the page for seconds. Layout now runs in a worker:
the canvas keeps its current drawing, says "Laying out…" if the worker
takes longer than 300 ms, and swaps the new positions in when they arrive.
A layout that a newer one replaces is dropped, and a worker failure is
shown on the canvas rather than leaving it blank.
…dden through live updates

A card removed from the canvas (Backspace on a selected card) left its
edges in the next layout request, so the layout failed and the error panel
replaced the graph. A request now carries only the edges between the cards
it sends, and an answer skips a card removed while it ran.

On a job run's graph, a live update during a layout replaced the class of
cards still waiting for their places, so they showed at unlaid positions
until the layout answered. They keep their mark now.

A layout that replaces a running one keeps the folder the user opened in
view, and a card keeps the size the canvas measured during a layout.
The anchor a folder click sets now waits for a layout to answer, so a
layout that replaces the click's layout keeps that folder in view. An
anchor must not outlive an explicit fit, though: Expand all clicked while
a folder's layout ran panned to that folder instead of placing the whole
graph. A fit, a reset and a failed layout now drop the anchor.
Svelte Flow's default delete key removed a selected card and its edges
from the canvas, which no page offers; the next layout then read edges to
a card that was gone and replaced the graph with an error. The canvas
turns the key off. With no other way for the canvas to drop a card, the
layout again fails loudly if it is ever asked to place one it doesn't
draw, rather than filtering the edges that name it.
Only the folder layout checked its edges' ends; the others passed such an
edge to dagre, which failed with "Cannot read properties of undefined
(reading 'push')". The input check every layout runs now names the edge
and the missing card, so a graph builder's slip reads from the error
panel.
# Conflicts:
#	ui/src/lib/lineage/member-graph.ts
#	ui/src/routes/runs/[id]/run-lineage.svelte
@chio-labs-delivery
chio-labs-delivery Bot added this pull request to the merge queue Dec 6, 2026
Any commits made after this event will not be merged.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Dec 6, 2026
@chio-labs-delivery
chio-labs-delivery Bot added this pull request to the merge queue Dec 6, 2026
Any commits made after this event will not be merged.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant