Skip to content

Add benchmarks and render Package.swift 5x faster - #32

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

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

Conversation

@mackoj

@mackoj mackoj commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Stacked on #31 (base chore/architecture-rules); GitHub retargets it to main once #31 merges.

What

  1. Pure core extracted (no behaviour change). renderSingleTarget, generateTargetsSection and the dependency-graph metrics moved out of PackagePlugin files into TargetRendering.swift and DependencyGraph.swift, which report warnings through a closure. New renderPackageContent builds the whole generated text; writeOutput now calls it. filterImports takes an optional remark closure instead of verbose:. The test target links the new files, and TargetRenderingTests checks a whole rendered file byte for byte.
  2. Benchmarks/, a separate package on ordo-one/package-benchmark. It links the same pure files and runs them on a synthetic 1,000-target project (config decode, import filtering, dependency graph, products, whole Package.swift). Also includes the p50/hotspots tools and scripts/profile.sh. CI builds it without running it (jemalloc disabled on the runner).
  3. Performance work, guided by Time Profiler:
    • the sort comparator in generateTargetsSection called pragmaMarkGroupName twice per comparison, which was 50% of render time. The group is now computed once per target.
    • renderSingleTarget rebuilt Set(appleDefaultSDKs) (272 strings) for every target. It now uses appleDefaultSDKSet, built once.
    • count(where:) / contains(where:) instead of filtering into arrays in the graph metrics.
  4. Architecture rules now also check the benchmarks' Shared links, and the SDK-filtering rule knows the new set.

Before → after (p50, 1,000 targets, Apple silicon)

Benchmark Wall clock p50 (µs) Mallocs p50
Render Package.swift, 1,000 targets 42,598 → 8,552 (0.20x) 154,605 → 35,631 (0.23x)
Render Package.swift, default settings 38,273 → 8,372 (0.22x) 147,124 → 35,537 (0.24x)
Dependency graph, 1,000 targets 1,213 → 834 (0.69x) 5,003 → 29 (0.01x)
Decode config / Filter imports / Render products unchanged (code untouched) unchanged

Output is unchanged

  • cmp on the 1.1 MB synthetic render (both configs, warnings, graph metrics, decoded config) gives the same bytes before and after.
  • End to end: I ran the plugin on a sample consumer package from main and from this branch, and the generated Package_generated.swift files are identical.
  • swift test (27 tests) and swift test --package-path Architecture pass.

This deserves a patch release (1.0.6) once merged. I could not merge it because branch protection requires a review.

Move renderSingleTarget, generateTargetsSection and the dependency graph
metrics into PackagePlugin-free files that report warnings through a
closure, and add renderPackageContent for the whole generated text. The
tests now link them and cover the rendered file byte for byte. Output is
unchanged.
A separate Benchmarks/ package links the plugin's PackagePlugin-free files
and measures config decoding, import filtering, the dependency graph and
rendering on a synthetic 1,000-target project. Includes the p50 and
hotspots tools and scripts/profile.sh. CI builds the benchmarks.
Compute each target's pragma-mark group once instead of in the sort
comparator, build the Apple SDK set once instead of per target, and count
local dependencies without building arrays. Output is byte for byte the
same. Document the benchmarks and results in docs/performance.md.
This was referenced Nov 14, 2026
@mackoj
mackoj merged commit c8e5506 into chore/architecture-rules Nov 14, 2026
1 check 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