Skip to content

compiler: match recursive edge selectors against existing connections - #2979

Merged
alixander merged 3 commits into
masterfrom
perf/indexed-edge-selectors
Nov 19, 2026
Merged

alixander merged 3 commits into
masterfrom
perf/indexed-edge-selectors

Conversation

@alixander

@alixander alixander commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Human


AI

Closes #2946.

The reported diagram has 400 SQL columns and zero connections. Four global connection styles made the compiler consider pairs of columns until it reached the edge expansion limit.

For selectors such as (** -> **)[*] and (*** -> ***)[*], the compiler tracks which branches contain connections. Sparse diagrams scan existing edges. When there are many parallel connections between a few endpoints, probing the existing endpoint-pair index can take less work. The selector uses that index when the visible endpoint pairs fit within the cost of an edge scan. Both paths preserve match order and honor the compiler limits.

Performance

The styled issue example now renders to the same SVG as the unstyled control, byte for byte. Its median CLI-reported render time was 21 ms across five runs. A second fixture exposed a regression in the first version of this PR. A leading undirected rule and 365 directed connections between two nodes had exhausted the default work limit. The revised selector compiles all 365 connections.

On an Apple M4 with Go 1.27, ten alternating samples of the full graph compiler gave these medians for two four-column SQL tables with one relationship.

Fixture CPU time per compile, base → PR Bytes allocated per compile
Style declared before the tables 936 µs → 73 µs 852 → 92 KiB
Style declared after the relationship 134 µs → 77 µs 147 → 78 KiB

One pass through all ten unmodified real-world fixtures used 8.144 MiB on the base and 8.144 MiB on this branch. Across 20 additional paired samples, median CPU time for compiling all ten was 11.64 ms on the base and 11.87 ms on this branch. Rendering all ten with Dagre took 338 ms and 333 ms respectively across eight paired samples. Both differences were within run-to-run variation. The branch index adds one pointer to each IR map and field on this architecture.

All ten unmodified fixtures produced identical Dagre SVGs across revisions. Adding a global directed-edge style to each fixture made five reach the base compiler's expansion limit. This branch rendered all ten and produced identical SVGs for the five that completed on both versions.

Testing

Ran go test ./..., go vet ./..., and go test -race ./d2ir ./d2compiler ./d2lib. Regression tests cover sparse schemas, column endpoints, imports, board scope, arrow direction, connection order, and parallel edges under default and custom work limits.

  • sent from alixander's Codex

@alixander
alixander merged commit c728d90 into master Nov 19, 2026
13 checks passed
@alixander
alixander deleted the perf/indexed-edge-selectors branch November 19, 2026 18:28
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.

[bug: v0.9.0] Rendering shape: sql_table takes an unusually long time

1 participant