Skip to content

Benchmarks and faster scheme rendering - #10

Merged
mackoj merged 2 commits into
chore/architecture-rulesfrom
perf/benchmarks
Nov 14, 2026
Merged

mackoj merged 2 commits into
chore/architecture-rulesfrom
perf/benchmarks

Conversation

@mackoj

@mackoj mackoj commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Stacked on #9 (base retargets to main once #9 merges).

What

  • Benchmarks/: a separate package on package-benchmark (wall clock, CPU, mallocs, peak memory, retains). The plugin target cannot be imported, so the benchmark target compiles Plugins/SchemeGeneratorPlugin/Core through a symlink. It measures everything a run does except the disk: hashing the product list, planning, rendering. Tools/P50, Tools/Hotspots and scripts/profile.sh as in swift-arazzo; documented in docs/performance.md.
  • CI builds the benchmarks (not run), with BENCHMARK_DISABLE_JEMALLOC=true.
  • Performance, same output byte for byte (new tests compare against the old replacingOccurrences and String(format:) code on ASCII, non-ASCII and placeholder-like names):
    • the template is split at __LIBRARY__ once and each scheme is appended into a pre-sized string, encoded with Data(string.utf8);
    • the product-list hash is hex-encoded with a lookup table instead of String(format: "%02x") per byte;
    • scheme file names compare utf8.count instead of count.

Before → after (p50, M-series Mac, Swift 6.4, release)

Benchmark Wall clock p50 (µs) Mallocs p50
Full run without disk, 1000 products 15368 → 1731 (0.11x) 6388 → 3026 (0.47x)
Render schemes, 1000 products 13369 → 519 (0.04x) 4100 → 1000 (0.24x)
Render and encode schemes, 1000 products 14066 → 729 (0.05x) 6100 → 3000 (0.49x)
Hash product names, 100 products 48 → 7 (0.15x) 273 → 11 (0.04x)
Read scheme names, 1000 files 371 → 267 (0.72x) 1912 → 1912
Plan schemes, 1000 products 803 → 782 19 → 19

The profile now puts the remaining time in sorting the plan (deterministic order) and string appends; writing the files dominates a real run and is not benchmarked.

…at:)

The full run without disk for 1,000 products drops from 15.4 ms to 1.7 ms
and from 6,388 to 3,026 mallocs. Output is byte for byte the same.
@mackoj mackoj mentioned this pull request Nov 14, 2026
@mackoj
mackoj merged commit 03f9d05 into chore/architecture-rules Nov 14, 2026
2 checks passed
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