Skip to content

Reduce Dagre, text measurement, and rendering overhead - #2880

Merged
alixander merged 8 commits into
masterfrom
agent/pipeline-performance-2
Sep 7, 2026
Merged

alixander merged 8 commits into
masterfrom
agent/pipeline-performance-2

Conversation

@alixander

@alixander alixander commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

Human


AI

Reduce repeated work during layout, text measurement, SVG preparation and PNG encoding:

  • Update Dagro to v0.2.1, incorporating the ranking/traversal improvements in Reduce Dagre ranking traversals and adjacency allocations dagro#4.
  • Measure glyph bounds without per-character heap rectangles and reuse font faces within a Ruler.
  • Build the font text corpus with one string builder and skip JSON decoding when no icon URL needs normalization.
  • Skip Up-filter arithmetic for a PNG row identical to its predecessor. This is a four-line shortcut; more aggressive block variants were rejected after mixed-image regressions.

Geometry, SVG and PNG output bytes are unchanged. Font and layout scratch remains local to the owning Ruler/layout.

Benchmarks

Full CLI exports, including startup, compilation, layout, rendering and file output:

Diagram/export Before After Speedup
TPMJS Dagre SVG 163.57 ms 109.40 ms 1.50×
Spyre Dagre SVG 40.79 ms 36.78 ms 1.11×
Lion Reader Dagre SVG 33.17 ms 31.44 ms 1.06×
TPMJS Dagre PNG, 1× 934.28 ms 855.54 ms 1.09×
TPMJS Dagre PNG, default 2× 3150.94 ms 2986.98 ms 1.05×

Apple M4, Go 1.27.0, GOMAXPROCS=1, one warmup and six alternating baseline/candidate process pairs per case. Ratios divide variant medians. Baseline D2 is 70affc0e; measured candidate D2 is 8f5bd501d with Dagro 1b61d9e. The release dependency has the same Dagro source tree. With normal Go CPU settings, TPMJS SVG improves 1.33×. Across 13 inputs (10 real-world diagrams and three basics), geometric means are 1.07× Dagre SVG, 1.01× ELK SVG, 1.04× Dagre PNG and 1.03× ELK PNG. Small exports remain near their startup floor.

Component benchmarks:

Operation Before After
TPMJS Dagre layout 135.92 ms; 100.86 MB allocated 81.76 ms; 52.20 MB allocated
Mixed Markdown table measurement 1.412 ms; 34,982 allocations 0.714 ms; 5,647 allocations
Ordinary label measurement 7,760 bytes; 482 allocations 128 bytes; 5 allocations
Font text corpus, synthetic 10,000 labels 1.49 GB allocated 1.54 MB allocated

These time the named operation, not the whole diagram. Allocation bytes are cumulative traffic, not peak live memory. The flat PNG microbenchmark improves 1.58×; gradient, noise and mixed-margin cases remain effectively unchanged. Local timings contain system noise; unfavorable samples were retained and small differences should not be treated as guaranteed improvements.

Validation

  • Full Go tests, targeted race checks, vet, WASM build and Linux 386 test compilation.
  • All 672 E2E output hashes and 7,257 per-case phase invocation counts match the baseline; no golden changes.
  • All measured output bytes match across 62 CLI cases, plus normal-CPU and D2-only controls, using --omit-version to exclude version metadata.
  • Added frozen glyph/font-face oracles, corpus/hash normalization cases, scalar PNG-filter comparisons, mixed-image byte equality and retained-state checks.
  • Upstream Dagro additionally preserves 1,320 frozen layouts and 241 separately checked weighted ranking exchanges.

Reproduce the component benchmarks with GOMAXPROCS=1 go test -p 1 ./d2layouts/d2dagrelayout ./lib/textmeasure ./d2target ./d2cli -run '^$' -bench 'Benchmark(DagreRealWorld|MarkdownTableMetrics|RulerLabelMetrics|DiagramCorpus|DiagramHashJSON|RasterPNGEncoder|RasterPNGMixedContent)$' -benchmem. The PNG CLI cases use --scale 0.5 for effective 1×, except existing Lion Reader/Ross appendix behavior at 2×; the three default-density controls use 2×.

@alixander
alixander merged commit c058268 into master Sep 7, 2026
13 checks passed
@alixander
alixander deleted the agent/pipeline-performance-2 branch September 7, 2026 18:53
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