Repository navigation
Reduce Dagre ranking traversals and adjacency allocations - #4
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
Ranking repeatedly copied adjacency lists and traversed the same tree to compute cut values and update ranks. Reuse traversal buffers, record preorder/postorder during the existing low/lim walk, and enumerate immutable adjacency maps directly.
This preserves ranking arithmetic, iteration order, tie comparisons, solver termination and public slice ownership. It also avoids sorting canonical edge keys, validates direct tree-edge lookups, and keeps the UTF-16 fallback for non-ASCII IDs.
Benchmarks
D2's Dagre layout phase on existing real-world fixtures, including adapter work but excluding compilation, themes and text measurement:
Apple M4, Go 1.27.0, GOMAXPROCS=1; six alternating baseline/candidate process pairs after warmup, ten layout iterations per fixture per process. Ratios divide variant medians. Baseline is v0.2.0 (
36cc8dbe); candidate is1b61d9e. Fulcro's longer 100-iteration followup was effectively unchanged (4.85 → 4.81 ms); Mocha showed no material timing change. Allocation bytes are cumulative traffic, not peak memory. These are local measurements, not universal speedups.Validation
The accompanying D2 PR, d2lang/d2#2880, adds
BenchmarkDagreRealWorldand consumes Dagro v0.2.1. Reproduce there withGOMAXPROCS=1 go test ./d2layouts/d2dagrelayout -run '^$' -bench '^BenchmarkDagreRealWorld$' -benchmem -benchtime=10x.