Skip to content

Content Graph freezes the browser with a large site #1111

Open

Description

@epeicher

Part of #560, which #1105 delivered in part.

Reported in #560 (item 11): "A site within the lab's stress profile can lock the entire OpenStation shell for more than ten seconds just by opening Content Graph. The completed view is also too dense to read or operate meaningfully." The author measured 11.59 to 28.64 seconds to become usable in Chromium on a graph of roughly 8,890 nodes, with single main-thread blocks of 10.85 to 14.12 seconds. On trunk, the repulsion loop in src/content-graph/sim.ts compares every pair of nodes on each step (its own header says this is fine up to about 500 nodes), setData() in src/content-graph/scene.ts runs up to 90 of those steps synchronously before the first paint, and rebuildSprites() creates Pixi objects for every node and edge in the same turn. The author asks to move loading off the long synchronous path and to give large graphs a real display strategy.

Activity

  1. added
    factory
    on Nov 21, 2026
  2. epeicher commented on Nov 21, 2026

    @epeicher
    CollaboratorAuthor

    Factory intake: ACCEPT (risk low, surfaces: ui)

    Summary

    • Accepted, narrowed to the freeze: opening the Corkboard on a large site must stop blocking the browser.
    • The three causes named in the issue are all confirmed on trunk: all-pairs repulsion in sim.ts, 90 synchronous warm-up steps in setData(), and every Pixi object built in one turn by rebuildSprites().
    • A fourth cost found while reading is included: draw() repaints every edge and node on every frame, even when nothing moved.
    • Left out: the "too dense to read" half of the report. It is a display decision of its own and is listed as a follow-up.
    • Client-side only, inside src/content-graph/. No PHP, REST or payload change.

    Scope

    Build, in src/content-graph/ only:

    1. Repulsion that scales. In sim.ts, ForceSim.step() compares every pair of nodes (about 39.5 million pairs per step at 8,890 nodes). Above a node threshold, replace that loop with an approximation such as the Barnes-Hut quadtree the file's own header names. Put it in its own module next to sim.ts (scene.ts is already 2,271 lines). Keep the exact pairwise loop at or below the threshold, so small boards lay out exactly as today. Default threshold: about 500 nodes, the limit the header states; tune it by measurement. Pinned nodes, the co-located kick, MAX_VELOCITY and the drag falloff keep working.
    2. A warm-up bounded by time. setData() in scene.ts runs warmupStepLimit() steps before the first paint (layout.ts: 700 for boards up to 80 nodes, otherwise JOIN_WARMUP_STEPS = 90). For large boards, cap the synchronous warm-up by a small time budget rather than a step count, and let the layout finish settling on screen, which boards over 80 nodes already do. Boards up to 80 nodes still run to rest before first paint. tests/vitest/content-graph-layout.test.ts pins the current limits; change those assertions on purpose, not to make them pass.
    3. Sprites built in slices. rebuildSprites() creates a container, two Graphics and two Text objects per node, measures every label, and adds a Graphics per edge, all in one turn. On a large board, build them in batches across frames so the browser can paint and take input in between. Do not build a node's label or glyph Text until it would be visible (labels are hidden below zoom 0.55; in disc style the glyph only shows on hover or focus). A build must be cancellable: a second loadGraph() (a filter chip toggled mid-build) or closing the window drops the build in flight.
    4. Loading feedback that matches. In index.ts, loadGraph() calls scene.setData() and then sets the status, the notice, fitToView() and clearFocus() in the same turn. Keep "Loading graph…" and the late overlay (loading-overlay.ts) up until the board is built, then show the node and link counts as today. The toolbar search reads scene.getNodes(), so it must stay correct during a build.
    5. No full repaint when nothing changed. draw() clears and re-strokes every edge and touches every node on each tick, and the tick never stops. Skip the repaint when the sim is settled and the camera, focus, hover and node style are unchanged.

    Decided here, so nobody has to ask:

    • No Web Worker and no new build target. The work stays on the main thread in bounded slices.
    • No cap on the number of nodes and no change to what the board shows. That belongs to the follow-up.
    • Done means: on a site with about 9,000 published posts, opening the Corkboard never blocks the main thread for more than roughly half a second at a stretch in Chromium, and the dock, other windows and the Corkboard's own toolbar keep answering while it loads. The reviewer compares against trunk with the same data, seeded on both sites through factory/seed.sh.
    • Tests: extend tests/vitest/content-graph-sim.test.ts and content-graph-layout.test.ts rather than adding files. One case that the approximate repulsion still spreads a large board, one for the large-board warm-up limit.

    Left out: a display strategy for large boards. Once loaded, a board of this size is still too dense to read or operate. See Follow-ups.

    Why

    The freeze is real and its causes are where the issue says: at 8,890 nodes the warm-up alone is 90 steps of about 39.5 million pair comparisons before the first paint, and the same loop then runs once per frame until the layout cools. That part has one clear outcome (the browser stays responsive) and fits one PR in one folder. How a board of thousands of posts should look is a separate question with several possible answers, so it is left for its own issue rather than guessed at here. Risk is low because the change stays in the Corkboard's client code: no documented public surface, no stored data, and nothing that decides who can read what. Boards under the threshold keep today's exact layout path.

    Follow-ups

    Content Graph: make a large board readable once it has loaded

    Reported in #560 (item 11): on a graph of roughly 8,890 nodes the completed view is "too dense to read or operate meaningfully", and #1111 asks for a real display strategy for large graphs. This is what is left after the load no longer freezes the browser. The place to start is draw() and fitToView() in src/content-graph/scene.ts: at overview zoom every node and every edge is painted, labels are hidden below zoom 0.55, and the fit is clamped at ZOOM_MIN (0.15), so a board this size may not even fit in the window. Keep it client-side. A change to the /content-graph/nodes payload needs a maintainer's green light first.

  3. added
    factory:needs-human
    and removed
    factory:needs-human
    on Nov 21, 2026
  4. epeicher commented on Nov 21, 2026

    @epeicher
    CollaboratorAuthor

    Factory: merged

    PR #1114 delivers the part of this issue that the intake comment above scoped. The rest is queued as #1116, each built as a PR of its own. This issue stays open until they land. It leaves the factory's queue.

  5. removed
    factory
    on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions