Skip to content

Commit 4d15ff2

Browse files
MaxDesiatovfurby-tm
authored andcommitted
Add basic thresholds for PackageGraphBenchmarks.swift (swiftlang#7462)
This records thresholds for two relatively stable metrics: total malloc count and total number of syscalls. We don't run these benchmarks on CI yet, but now it allows tracking regressions locally.
1 parent 1408590 commit 4d15ff2

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

Benchmarks/Benchmarks/PackageGraphBenchmarks/PackageGraphBenchmarks.swift

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
import Basics
22
import Benchmark
3+
import Foundation
34
import PackageModel
45
import Workspace
56

67
let benchmarks = {
8+
let defaultMetrics: [BenchmarkMetric]
9+
if let envVar = ProcessInfo.processInfo.environment["SWIFTPM_BENCHMARK_ALL_METRICS"],
10+
envVar.lowercased() == "true" || envVar == "1" {
11+
defaultMetrics = .all
12+
} else {
13+
defaultMetrics = [
14+
.mallocCountTotal,
15+
.syscalls,
16+
]
17+
}
18+
19+
// Benchmarks computation of a resolved graph of modules for a package using `Workspace` as an entry point. It runs PubGrub to get
20+
// resolved concrete versions of dependencies, assigning all modules and products to each other as corresponding dependencies
21+
// with their build triples, but with the build plan not yet constructed. In this benchmark specifically we're loading `Package.swift`
22+
// for SwiftPM itself.
723
Benchmark(
8-
"Package graph loading",
24+
"SwiftPMWorkspaceModulesGraph",
925
configuration: .init(
10-
metrics: BenchmarkMetric.all,
11-
maxDuration: .seconds(10)
26+
metrics: defaultMetrics,
27+
maxDuration: .seconds(10),
28+
thresholds: [
29+
.mallocCountTotal: .init(absolute: [.p90: 12000]),
30+
.syscalls: .init(absolute: [.p90: 1600]),
31+
]
1232
)
1333
) { benchmark in
1434
let path = try AbsolutePath(validating: #file).parentDirectory.parentDirectory.parentDirectory

Benchmarks/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SwiftPM Benchmarks
2+
3+
Benchmarks currently use [ordo-one/package-benchmark](https://github.com/ordo-one/package-benchmark) library for benchmarking.
4+
5+
## How to Run
6+
7+
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):
8+
```
9+
swift package benchmark
10+
```
11+
12+
To collect all benchmark metrics, set `SWIFTPM_BENCHMARK_ALL_METRICS` to a truthy value:
13+
14+
```
15+
SWIFTPM_BENCHMARK_ALL_METRICS=true swift package benchmark
16+
```
17+
18+
## Benchmark Thresholds
19+
20+
`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:
21+
22+
```
23+
swift package --allow-writing-to-package-directory benchmark --format metricP90AbsoluteThresholds --path Thresholds/
24+
```
25+
26+
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:
27+
28+
```
29+
swift package benchmark baseline check --check-absolute-path Thresholds/
30+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"mallocCountTotal" : 9535,
3+
"syscalls" : 1496
4+
}

0 commit comments

Comments
 (0)