Skip to content

Optimize svgbob rendering hot paths - #125

Open
exlee wants to merge 1 commit into
ivanceras:masterfrom
exlee:axk-optimization-work
Open

Optimize svgbob rendering hot paths#125
exlee wants to merge 1 commit into
ivanceras:masterfrom
exlee:axk-optimization-work

Conversation

@exlee

@exlee exlee commented Jul 10, 2026

Copy link
Copy Markdown

I am evaluating svgbob as a library backend for my DiagramIDE app.
Before integrating it as another diagram output language, I profiled the
renderer (current Pikchr output is mindboggingly fast) and found some scaling
problems on larger connected diagrams.

I used GPT-5.6 as an optimization partner while investigating the hot paths, and
wanted to share the concrete results with the upstream project.

I do not have any expectations toward handling this PR. If it's not aligning
with project direction or personal views, feel free to disregard it - I merely
found a value in it and thought it's share-worthy.

Results

Release build benchmark using svgbob_cli, with three warmup runs and eight
timed runs per fixture:

Fixture Before After Improvement
simple.bob 25.7 ms 9.1 ms 2.8x
demo.bob 864.1 ms 50.9 ms 17.0x
long.bob 2037 ms 152.9 ms 13.3x
circles.bob 167.9 ms 17.7 ms 9.5x
example.bob 295.9 ms 39.3 ms 7.5x

The generated SVGs were byte-for-byte identical for all five fixtures.

What changed

  • Replaced recursive all-pairs span merging with indexed union-find
    connectivity over neighboring cells, while preserving input order.
  • Cached fragment bounds when constructing FragmentTree nodes instead of
    recalculating geometry bounds during every containment comparison.
  • Localized circle and arc candidates once per search span.
  • Made failed circle/arc subset checks return immediately when a required
    template cell is absent, avoiding the second scan for unmatched cells.
  • Added a regression test covering transitive span connectivity.
  • Refreshed the stale lockfile package metadata from 0.7.5 to 0.7.6.

Verification

  • cargo test --offline -p svgbob
    • 105 unit tests passed
    • 5 simple_shapes integration tests passed
    • styling integration test passed
    • doc tests passed or remained intentionally ignored
  • cargo fmt --all -- --check passed.
  • Release benchmarks and SVG byte comparisons passed.

cargo clippy --offline -p svgbob --all-targets -- -D warnings still reports
24 existing upstream lint findings in untouched code; none are introduced by
these changes.

LLM Disclaimer

I've set search boundary condition, harness, search requirements and let GPT 5.6 Sol/Luna run.
There wasn't much work on my side toward this contribution, outside of preparing this PR and validating result.

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