Skip to content

Add basic thresholds for PackageGraphBenchmarks.swift #7462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 17, 2024
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
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
import Basics
import Benchmark
import Foundation
import PackageModel
import Workspace

let benchmarks = {
let defaultMetrics: [BenchmarkMetric]
if let envVar = ProcessInfo.processInfo.environment["SWIFTPM_BENCHMARK_ALL_METRICS"],
envVar.lowercased() == "true" || envVar == "1" {
defaultMetrics = .all
} else {
defaultMetrics = [
.mallocCountTotal,
.syscalls,
]
}

// Benchmarks computation of a resolved graph of modules for a package using `Workspace` as an entry point. It runs PubGrub to get
// resolved concrete versions of dependencies, assigning all modules and products to each other as corresponding dependencies
// with their build triples, but with the build plan not yet constructed. In this benchmark specifically we're loading `Package.swift`
// for SwiftPM itself.
Benchmark(
"Package graph loading",
"SwiftPMWorkspaceModulesGraph",
configuration: .init(
metrics: BenchmarkMetric.all,
maxDuration: .seconds(10)
metrics: defaultMetrics,
maxDuration: .seconds(10),
thresholds: [
.mallocCountTotal: .init(absolute: [.p90: 12000]),
.syscalls: .init(absolute: [.p90: 1600]),
]
)
) { benchmark in
let path = try AbsolutePath(validating: #file).parentDirectory.parentDirectory.parentDirectory
Expand Down
30 changes: 30 additions & 0 deletions Benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SwiftPM Benchmarks

Benchmarks currently use [ordo-one/package-benchmark](https://github.com/ordo-one/package-benchmark) library for benchmarking.

## How to Run

To run the benchmarks in their default configuration, run this commend in the `Benchmarks` subdirectory of the SwiftPM repository clone (the directory in which this `README.md` file is contained):
```
swift package benchmark
```

To collect all benchmark metrics, set `SWIFTPM_BENCHMARK_ALL_METRICS` to a truthy value:

```
SWIFTPM_BENCHMARK_ALL_METRICS=true swift package benchmark
```

## Benchmark Thresholds

`Benchmarks/Thresholds` subdirectory contains recorded allocation and syscall counts for macOS on Apple Silicon when built with Swift 5.10. To record new thresholds, run the following command:

```
swift package --allow-writing-to-package-directory benchmark --format metricP90AbsoluteThresholds --path Thresholds/
```

To verify that recorded thresholds do not exceeded given relative or absolute values (passed as `thresholds` arguments to each benchmark's configuration), run this command:

```
swift package benchmark baseline check --check-absolute-path Thresholds/
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"mallocCountTotal" : 9535,
"syscalls" : 1496
}