Repository navigation
feat(layout): choose the engine by an estimate of the layout, refuse one elkjs cannot finish - #270
Merged
Merged
Conversation
…use one elkjs cannot finish A layered layout is costed before it runs (`server/layout-cost.ts`). A pass is what one container lays out: its nodes are layered by their longest path, as ELK layers them, and the cost is the sum of the layers each edge spans. Rates measured on the platform's own presets turn it into milliseconds for elkjs and for the ELK server. - `auto` sends a graph to the server when elkjs is estimated to need more than a second for it, not past 150 nodes or 400 edges. Of two graphs of 150 nodes on the default preset, elkjs lays one out in 0.7 s and the other in 21 s. - A layout the server was asked for and did not answer is refused when elkjs is estimated to take longer than the server's timeout. The diagram says so on its status line and stays as it was. - Every layout logs its estimate beside the time it took. The cycles of a graph are broken as ELK breaks them (its greedy order), and a port of a container that an edge of the inside ends on is a node of the pass. Without the two, a synthesised netlist was costed seven times too deep and a unit drawn open at less than half. The rates are a least-squares fit to 84 generated networks of 30 to 10,000 nodes (`test/layout-rates.measure.test.ts`, `scripts/fit-layout-rates.mjs`), each within a factor of two of its estimate on both engines, and were checked on seven graphs of picorv32 they were not fitted to. Stage 8.5b of the mlir-viewer convergence plan, the platform half. Claude-Session: https://claude.ai/code/session_01EToj6NxqLABK3H5cucHNsY
- A layout that fails leaves the diagram as it was. The layout commands clear every edge route before ELK is asked, and Untangled and Free Ports move the ports first: a refused layout left straight edges and the new port order in the model. The routes (`layoutFromClearedRoutes`) and the ports are put back, for any failure. - The options a layout command sets for its own run are taken off again when the layout fails, in the boundary-flow and serpentine handlers too. - The refusal has a threshold of its own: the server's timeout, and no less than a minute (`elkjsTakeoverMs`). A short timeout no longer refuses a graph elkjs lays out in seconds. - A Free Ports layout is refused at its probe. It used to swallow the refusal and ask the server for the same graph again, waiting the timeout twice. The status line is told once, for the probe, the layout and the pinned band. - Nodes another algorithm than the layered one lays out are in no estimate. They are counted (`unpriced`), and `auto` keeps the size rule for them: such a graph was estimated at nothing and never went to the server. - The options of Untangled and Free Ports over the default preset are a preset of their own, `untangled`, measured on 24 graphs: about three times the middle preset, which they were priced as. Claude-Session: https://claude.ai/code/session_01EToj6NxqLABK3H5cucHNsY
This was referenced Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stage 8.5b of the mlir-viewer convergence plan, the platform half. The mlir-viewer half follows (its
layout-cost.tskeeps what is MLIR's and calls this estimate).What changes for a user
autochooses the engine by what the layout is estimated to take. A graph goes to the ELK server when elkjs is estimated to need more than a second for it (AUTO_ELKJS_BUDGET_MS). The rule before was 150 nodes or 400 edges, which said little: of two graphs of 150 nodes on the default preset, elkjs lays one out in 0.7 s and the other in 21 s (the server in 0.2 s and 2.5 s).LayoutRefusedErrorwhen elkjs is estimated to take longer than the server's timeout, or than a minute when the timeout is shorter, and the diagram says so on its status line. A graph elkjs can finish in time still falls back, and with no server at all (no Java, no jar) elkjs takes everything as before.[dialogram layout] elkjs: 40 nodes, 110 edges in 229 ms (estimated 228 ms).The estimate (
server/layout-cost.ts)layerSpan).estimatePassMsturns a costed pass into milliseconds with the rates of an engine.estimateElkLayoutdoes both for an ELK graph, with the rates of the preset its options ask for.counted: falsefor edges that only order,orders: falsefor edges against the flow). That is what mlir-viewer does next.The rates
test/layout-rates.measure.test.ts(runs only withDIALOGRAM_MEASURE_LAYOUT), fitted byscripts/fit-layout-rates.mjs: least squares on relative error, fewest terms within a tenth of the best fit.test/fixtures/layout-rates/measured.jsonl, held by a test).untangled), measured on 24 more graphs: about three times the middle preset.checked.jsonl).After the review
elkjsTakeoverMs).unpriced), andautokeeps the size rule for them.untangledpreset.Found on the way, not in this PR
NetworkSimplex.tightTreeDFSoverflows the stack, the server logsError: nulland leaves the request open, so the client waits out the whole timeout.-Xss64mcures it (10,000 and 20,000 nodes laid out). A follow-up PR.Checks
packages/diagram-server: 148 files, 1,146 tests pass. Type check clean.scripts/check-neutrality.shpasses.https://claude.ai/code/session_01EToj6NxqLABK3H5cucHNsY