Repository navigation
Reduce Dagre, text measurement, and rendering overhead - #2880
Merged
Merged
Conversation
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.
Human
AI
Reduce repeated work during layout, text measurement, SVG preparation and PNG encoding:
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:
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 is8f5bd501dwith Dagro1b61d9e. 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:
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
--omit-versionto exclude version metadata.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.5for effective 1×, except existing Lion Reader/Ross appendix behavior at 2×; the three default-density controls use 2×.