Skip to content

Commit 601a312

Browse files
author
David Ungar
committed
add write priors test
1 parent a5a93d5 commit 601a312

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ extension ModuleDependencyGraph {
868868
}
869869
}
870870

871-
fileprivate final class Serializer {
871+
@_spi(Testing) public final class Serializer {
872872
let internedStringTable: InternedStringTable
873873
let compilerVersion: String
874874
let serializedGraphVersion: Version

Tests/SwiftDriverTests/CleanBuildPerformanceTests.swift

+25-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import TSCBasic
77
import TSCUtility
88

99
class CleanBuildPerformanceTests: XCTestCase {
10+
enum WhatToMeasure { case reading, writing }
11+
1012
/// Test the cost of reading `swiftdeps` files without doing a full build. Use the files in "TestInputs/SampleSwiftDeps"
1113
///
1214
/// When doing an incremental but clean build, after every file is compiled, its `swiftdeps` file must be
@@ -20,6 +22,15 @@ class CleanBuildPerformanceTests: XCTestCase {
2022
/// `cd` to the package directory, then:
2123
/// `rm TestInputs/SampleSwiftDeps/*; rm -rf .build; swift build; find .build -name \*.swiftdeps -a -exec cp \{\} TestInputs/SampleSwiftDeps \;`
2224
func testCleanBuildSwiftDepsPerformance() throws {
25+
try testCleanBuildPerformance(.reading)
26+
}
27+
func testCleanBuildSavingPriorsPerformance() throws {
28+
try testCleanBuildPerformance(.writing)
29+
}
30+
31+
32+
func testCleanBuildPerformance(_ whatToMeasure: WhatToMeasure) throws {
33+
2334
#if !os(macOS)
2435
// rdar://81411914
2536
throw XCTSkip()
@@ -37,7 +48,7 @@ class CleanBuildPerformanceTests: XCTestCase {
3748
let limit = 100 // This is the real test, optimized code.
3849
#endif
3950

40-
try test(swiftDepsDirectory: swiftDepsDirectoryPath.pathString, atMost: limit)
51+
try test(swiftDepsDirectory: swiftDepsDirectoryPath.pathString, atMost: limit, whatToMeasure)
4152
}
4253

4354
/// Test the cost of reading `swiftdeps` files without doing a full build.
@@ -49,13 +60,24 @@ class CleanBuildPerformanceTests: XCTestCase {
4960
/// - Parameters:
5061
/// - swiftDepsDirectory: where the swiftdeps files are, either absolute, or relative to the current directory
5162
/// - limit: the maximum number of swiftdeps files to process.
52-
func test(swiftDepsDirectory: String, atMost limit: Int = .max) throws {
63+
func test(swiftDepsDirectory: String, atMost limit: Int = .max, _ whatToMeasure: WhatToMeasure) throws {
5364
let (outputFileMap, inputs) = try createOFMAndInputs(swiftDepsDirectory, atMost: limit)
5465

5566
let info = IncrementalCompilationState.IncrementalDependencyAndInputSetup
5667
.mock(options: [], outputFileMap: outputFileMap)
5768
let g = ModuleDependencyGraph(info, .updatingAfterCompilation)
58-
measure {readSwiftDeps(for: inputs, into: g)}
69+
switch whatToMeasure {
70+
case .reading:
71+
measure {readSwiftDeps(for: inputs, into: g)}
72+
case .writing:
73+
readSwiftDeps(for: inputs, into: g)
74+
measure {
75+
ModuleDependencyGraph.Serializer.serialize(
76+
g,
77+
"mock compiler version",
78+
ModuleDependencyGraph.serializedGraphVersion)
79+
}
80+
}
5981
}
6082

6183
/// Build the `OutputFileMap` and input vector for ``testCleanBuildSwiftDepsPerformance(_, atMost)``

0 commit comments

Comments
 (0)