Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/performance-study.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,69 @@ jobs:
archunit/benchmark/study/Gemfile.lock
if-no-files-found: warn
retention-days: 14

discovery:
if: github.event_name == 'workflow_dispatch'
name: Paired discovery — ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
path: candidate
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
ref: v1.1.0
path: baseline
persist-credentials: false
- uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1
with:
ruby-version: '4.0'
bundler-cache: true
working-directory: candidate
- name: Run alternating fresh-process pairs with the existing extraction benchmark
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$candidate = Join-Path $env:GITHUB_WORKSPACE 'candidate'
$baseline = Join-Path $env:GITHUB_WORKSPACE 'baseline'
$reports = Join-Path $env:GITHUB_WORKSPACE 'reports'
New-Item -ItemType Directory -Path $reports -Force | Out-Null
Copy-Item -LiteralPath (Join-Path $candidate 'benchmark/extraction.rb') -Destination (Join-Path $baseline 'benchmark/extraction.rb')
$env:BUNDLE_PATH = Join-Path $candidate 'vendor/bundle'
$cases = @(
@{name='sparse-5000'; files=5000; imports=0; excluded=0},
@{name='sparse-10000'; files=10000; imports=0; excluded=0},
@{name='imports-1000'; files=1000; imports=3; excluded=0},
@{name='excluded-1000'; files=1000; imports=0; excluded=3000}
)
foreach ($case in $cases) {
foreach ($trial in 1..3) {
$results = @{}
foreach ($side in 'baseline','candidate') {
$checkout = if ($side -eq 'baseline') { $baseline } else { $candidate }
$env:BUNDLE_GEMFILE = Join-Path $checkout 'Gemfile'
$output = Join-Path $reports "$($case.name)-$trial-$side.json"
bundle exec ruby (Join-Path $checkout 'benchmark/extraction.rb') --files $case.files --gems 2 --imports-per-file $case.imports --excluded-files $case.excluded --constants --output $output | Out-Null
if ($LASTEXITCODE -ne 0) { throw "Failed $($case.name) / $side" }
$results[$side] = Get-Content -LiteralPath $output -Raw | ConvertFrom-Json
if (-not $results[$side].graph_cache_reused) { throw 'Graph cache was not reused' }
if ($results[$side].cold.counters.source_files -ne ($case.files + 1)) { throw 'Wrong source inventory' }
Write-Output "$($case.name) trial=$trial side=$side cold=$($results[$side].cold.stage_seconds.total) discovery=$($results[$side].cold.stage_seconds.source_enumeration) allocated=$($results[$side].cold.memory_growth.allocated_objects)"
}
if ($results.baseline.graph_sha256 -ne $results.candidate.graph_sha256) { throw 'Graph or retained evidence changed' }
}
}
- name: Retain raw paired measurements
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: discovery-${{ matrix.os }}-${{ github.run_id }}
path: reports/*.json
if-no-files-found: error
retention-days: 14
7 changes: 6 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ Without a locator, ArchUnitRuby searches upward for a `Gemfile` or gemspec.

Discovery skips symlinked source files and directories, including aliases inside the project root.
Direct `FileInfo` extraction validates canonical as well as lexical containment before reading.
The source walker reuses a single file-status result per entry for type and symlink decisions.
The source walker owns a pruned iterative traversal and reuses one status per entry. Identifiers
come from directory child components under the canonical root, not unchecked absolute-prefix
slicing; the final source list is sorted once. Included entry/listing failures raise
`TechnicalError`, including unreadable or disappearing directories; they are not silently skipped.
This stricter listing-error handling is part of unreleased 1.1.1. Excluded directories are pruned
before their children are listed. Concurrent hostile filesystem mutation is not sandboxed.

The detected root's `.archignore` is applied centrally to graphs and file-based metrics. It accepts
blank lines, full-line `#` comments, basename globs, root-relative path globs, leading `/` anchors,
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 1.1.1 (unreleased)

- Reuse one source-entry status, compile exclusion matching once, and build relative identifiers
from directory children in a pruned iterative source walker, preserving sorted graph inputs.
- Fail closed on unreadable/disappearing included directory listings instead of inheriting Find's
silent listing-error skip. Excluded trees are still pruned without opening their descendants.
- Extend the existing extraction benchmark with allocation counts, full graph/evidence digests,
and excluded-tree workloads; retain generous CI timing ceilings.

## 1.1.0 - 2026-11-23

Additive release over 1.0.0. Import-only analysis remains the default; the CLI and Rails helpers
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
archunit (1.1.0)
archunit (1.1.1)
csv (>= 3.3, < 4.0)
json (>= 2.7, < 3.0)
prism (>= 1.0, < 2.0)
Expand Down Expand Up @@ -114,7 +114,7 @@ DEPENDENCIES
yard (~> 0.9.45)

CHECKSUMS
archunit (1.1.0)
archunit (1.1.1)
ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
bundler-audit (0.9.3) sha256=81c8766c71e47d0d28a0f98c7eed028539f21a6ea3cd8f685eb6f42333c9b4e9
csv (3.3.7) sha256=15a3f16f6628da8664d455eb634e7f22031bcf53044923caf56975109e71b9f8
Expand Down
62 changes: 60 additions & 2 deletions benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,64 @@ pinned Rails production-source evidence, see the [representative study](study/RE
For pinned production-library compatibility checks, public passing/failing rule witnesses, and
real-world timing artifacts, see the [static canary guide](canary/README.md).

## Source-discovery follow-up (#100)

The same extraction benchmark now reports `cold.memory_growth.allocated_objects` and a
`graph_sha256` covering ordered edges and their structured source evidence. Allocation counts
are work performed during cold analysis, not retained-memory measurements. `--excluded-files N`
adds a deliberately malformed `vendor/` tree; source counts must still be requested files + 1
(the generator's shared source), and no excluded file may be parsed.

`retained` reports Ruby-heap growth after an explicit GC following both timed operations; this
extra GC is outside the cold/warm timers. Peak RSS remains a whole-process high-water mark,
including fixture generation, and pre-GC cold heap growth can vary with collection timing.

For example:

```sh
bundle exec ruby benchmark/extraction.rb --files 10000 --gems 2 --imports-per-file 0 --constants
bundle exec ruby benchmark/extraction.rb --files 1000 --excluded-files 3000 --constants
```

Manually dispatch `performance-study.yml` on the candidate ref to run three alternating fresh
baseline/candidate pairs for sparse 5k/10k, import-heavy and excluded-tree cases on Linux and
Windows. The discovery job uses the normal production bundle, v1.1.0 library baseline and the
identical updated `benchmark/extraction.rb` harness in both checkouts. It checks full graph/evidence
digests, actual source inventories and cached graph identity, and retains every JSON result.
No competitor backend is involved in these paired measurements. Normal PRs do not run the heavy
discovery matrix; existing generous extraction-smoke ceilings stay unchanged.

Local Windows x64 / Ruby 4.0.6 medians (2026-11-24; three pairs per case):

| Case | Before cold | After cold | Before discovery | After discovery | Before allocations | After allocations |
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
| Sparse 5,000 (+1 shared) | 6.891 s | 4.263 s | 3.494 s | 1.172 s | 5,209,871 | 2,627,199 |
| Sparse 10,000 (+1 shared) | 13.830 s | 7.839 s | 7.253 s | 1.948 s | 10,414,873 | 5,252,199 |
| 1,000 / three imports | 2.221 s | 1.490 s | 0.425 s | 0.126 s | 1,466,479 | 947,810 |
| 1,000 / 3,000 excluded | 1.420 s | 0.831 s | 0.774 s | 0.200 s | 1,046,126 | 527,204 |

[Every local sample](study/discovery-windows.json) is retained. All pairs have identical graph
and evidence digests, including source ordering. Timings depend on filesystem cache, host and
load; fixtures are freshly generated outside profiled analysis, not a cold-disk experiment.
Windows peak RSS is unavailable, not zero. Heap snapshots are not post-GC retained memory.
Do not turn these local medians into portable timing gates or a universal speed claim.

Hosted Linux/Windows verification (Ruby 4.0.10, three pairs per case) is retained in
[discovery-ci.json](study/discovery-ci.json), including separate post-GC measurements:

| 10,000-file case | Before cold | After cold | Before discovery | After discovery | Before allocations | After allocations |
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
| Linux | 1.750 s | 1.078 s | 0.716 s | 0.030 s | 8,453,786 | 4,891,912 |
| Windows | 5.922 s | 3.688 s | 3.228 s | 0.962 s | 9,064,085 | 5,102,011 |

Post-GC Ruby-heap growth for this case is essentially unchanged: Linux 8,417,117 to 8,414,189
bytes; Windows 8,414,189 to 8,414,077 bytes. This supports lower transient work, not a new claim
that every memory measure improves. Linux whole-process peak RSS drops from 97,212 to 83,144 KiB
at 10k, but rises from 58,760 to 64,408 KiB at 5k despite similar retained heap. Pre-GC growth is
similarly mixed; Windows RSS is unavailable. Warm lookup medians remain below 1.3 ms in these
samples, with one small Linux excluded-tree case increasing from 0.117 to 0.902 ms despite
confirmed graph reuse. Keep these tradeoffs visible rather than optimizing to a single number.

The benchmark generates a deterministic multi-gem Ruby repository, then measures one cold graph
build and one same-process cached lookup. Target application code and generated gemspecs are never
executed.
Expand Down Expand Up @@ -85,8 +143,8 @@ symlink-skipping walker on the same 1,000-file / 10-gem / 3-import corpus. Ruby
Every pair retained 4,001 graph edges and reused its cached graph. Warm lookups ranged from
3.6–11.0 ms. Enumeration improved in each pair, but the large run-to-run variation makes an exact
speedup claim inappropriate. This is evidence against an obvious regression, not a portable speed
guarantee. The walker now uses one explicit `lstat` result for its own type/symlink decisions;
Ruby's `Find` traversal still performs its own metadata checks.
guarantee. That audit used one explicit `lstat` result for its own type/symlink decisions;
Ruby's `Find` traversal still performed its own metadata checks at that revision.

### Original extraction baseline

Expand Down
48 changes: 42 additions & 6 deletions benchmark/extraction.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'fileutils'
require 'digest'
require 'json'
require 'objspace'
require 'optparse'
Expand All @@ -13,6 +14,7 @@ module ExtractionBenchmark
files: 1_000,
gems: 10,
imports_per_file: 3,
excluded_files: 0,
dependency_analysis: :imports,
max_cold_seconds: nil,
max_warm_seconds: nil,
Expand All @@ -21,19 +23,23 @@ module ExtractionBenchmark

# Deterministic multi-gem Ruby corpus with both repeated and cross-gem requires.
class Corpus
attr_reader :root, :file_count, :gem_count, :imports_per_file
attr_reader :root, :file_count, :gem_count, :imports_per_file, :excluded_file_count

def initialize(root, file_count:, gem_count:, imports_per_file:)
def initialize(root, file_count:, gem_count:, imports_per_file:, excluded_file_count: 0)
@root = root
@file_count = positive_integer(file_count, :files)
@gem_count = positive_integer(gem_count, :gems)
@imports_per_file = non_negative_integer(imports_per_file, :imports_per_file)
@excluded_file_count = non_negative_integer(excluded_file_count, :excluded_files)
end

def generate
gem_count.times { |index| write_gemspec(index) }
file_count.times { |index| write_source(index) }
write('packages/gem_00/lib/shared/common.rb', "# shared benchmark dependency\n")
excluded_file_count.times do |index|
write("vendor/generated/deep/file_#{index}.rb", "# excluded malformed generator\nclass <")
end
root
end

Expand Down Expand Up @@ -97,7 +103,7 @@ def write(relative_path, contents)
# Runs one cold graph build and one same-process graph-cache lookup.
class Runner
RunValues = Data.define(
:cold_graph, :cold_profile, :warm_graph, :warm_profile, :before, :after_cold
:cold_graph, :cold_profile, :warm_graph, :warm_profile, :before, :after_cold, :after_gc
)
private_constant :RunValues

Expand All @@ -123,7 +129,8 @@ def collect_values
after_cold = memory_snapshot
warm_graph, warm_profile = extract_profiled
RunValues.new(
cold_graph:, cold_profile:, warm_graph:, warm_profile:, before:, after_cold:
cold_graph:, cold_profile:, warm_graph:, warm_profile:, before:, after_cold:,
after_gc: retained_snapshot
)
end

Expand All @@ -138,18 +145,44 @@ def extract_profiled

def benchmark_result(values)
{
corpus: @configuration.slice(:files, :gems, :imports_per_file, :dependency_analysis),
corpus: corpus_description,
graph_edges: values.cold_graph.length,
graph_sha256: graph_digest(values.cold_graph),
graph_cache_reused: values.cold_graph.equal?(values.warm_graph),
cold: values.cold_profile.to_h.merge(memory_delta(values.before, values.after_cold)),
warm: values.warm_profile.to_h,
retained: retained_memory(values),
runtime: { ruby: RUBY_VERSION, platform: RUBY_PLATFORM }
}
end

def graph_digest(graph)
edges = graph.map { |edge| edge.to_h.merge(evidence: edge.evidence.map(&:to_h)) }
Digest::SHA256.hexdigest(JSON.generate(edges))
end

def corpus_description
@configuration.slice(:files, :gems, :imports_per_file, :excluded_files, :dependency_analysis)
end

def retained_snapshot
GC.start
memory_snapshot
end

def retained_memory(values)
{
ruby_heap_bytes: values.after_gc[:ruby_heap_bytes],
ruby_heap_growth_bytes: values.after_gc[:ruby_heap_bytes] - values.before[:ruby_heap_bytes],
heap_live_slots_growth: values.after_gc[:heap_live_slots] - values.before[:heap_live_slots],
process_peak_rss_kb: values.after_gc[:process_peak_rss_kb]
}
end

def memory_snapshot
{
ruby_heap_bytes: ObjectSpace.memsize_of_all,
allocated_objects: GC.stat(:total_allocated_objects),
heap_live_slots: GC.stat(:heap_live_slots),
process_peak_rss_kb: linux_peak_rss_kb
}
Expand All @@ -166,6 +199,7 @@ def memory_delta(before, after)
{
memory: after,
memory_growth: {
allocated_objects: after[:allocated_objects] - before[:allocated_objects],
ruby_heap_bytes: after[:ruby_heap_bytes] - before[:ruby_heap_bytes],
heap_live_slots: after[:heap_live_slots] - before[:heap_live_slots]
}
Expand Down Expand Up @@ -210,6 +244,7 @@ def configure_corpus_options(parser, options)
parser.on('--files N', Integer) { |value| options[:files] = value }
parser.on('--gems N', Integer) { |value| options[:gems] = value }
parser.on('--imports-per-file N', Integer) { |value| options[:imports_per_file] = value }
parser.on('--excluded-files N', Integer) { |value| options[:excluded_files] = value }
end

def configure_threshold_options(parser, options)
Expand All @@ -229,7 +264,8 @@ def run_in(directory, options)
directory,
file_count: options.fetch(:files),
gem_count: options.fetch(:gems),
imports_per_file: options.fetch(:imports_per_file)
imports_per_file: options.fetch(:imports_per_file),
excluded_file_count: options.fetch(:excluded_files)
).generate
payload = JSON.pretty_generate(Runner.new(directory, options).run)
write_payload(options[:output], payload)
Expand Down
4 changes: 2 additions & 2 deletions benchmark/study/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../..
specs:
archunit (1.1.0)
archunit (1.1.1)
csv (>= 3.3, < 4.0)
json (>= 2.7, < 3.0)
prism (>= 1.0, < 2.0)
Expand Down Expand Up @@ -32,7 +32,7 @@ DEPENDENCIES

CHECKSUMS
archspec (1.1.0) sha256=861d4869c81617139ea9e42e6de1456ba00d0538f3994476073829de223a754d
archunit (1.1.0)
archunit (1.1.1)
csv (3.3.7) sha256=15a3f16f6628da8664d455eb634e7f22031bcf53044923caf56975109e71b9f8
json (2.21.2) sha256=1f1d3b7cf2b3ba1a69beca0bb6db13d5438b80bff3cd54cdaaa620b9b07c1c6a
prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
Expand Down
5 changes: 5 additions & 0 deletions benchmark/study/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ RubyDEX 0.4.0, Prism 1.9.0, JSON 2.21.2 and CSV 3.3.7. Its lock contains Linux/W
package checksums without changing root dependencies. The candidate is the checkout revision,
not necessarily the published gem.

For the separate source-discovery optimization follow-up (#100), see the
[root extraction benchmark](../README.md#source-discovery-follow-up-100) and its paired-sample
JSON. The manual performance workflow also runs that unchanged generator/harness against the
v1.1.0 and candidate libraries on Linux/Windows, using only the normal production bundle.

## Shared-policy study

`run.rb` generates Rails-like and four-engine layouts with 200 Ruby files by default. Density
Expand Down
Loading