Skip to content

Commit e900d29

Browse files
authored
Add Benchmarking Target (#643)
* Benchmarks * CI * test * fix? * Fix
1 parent 5ca2b43 commit e900d29

File tree

8 files changed

+260
-7
lines changed

8 files changed

+260
-7
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app
2424
- name: Run tests
2525
run: make test-library
26+
- name: Run benchmark
27+
if: ${{ matrix.xcode != 11.3 }}
28+
run: make benchmark
2629

2730
examples:
2831
runs-on: macos-10.15
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1250"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "swift-composable-architecture-benchmark"
18+
BuildableName = "swift-composable-architecture-benchmark"
19+
BlueprintName = "swift-composable-architecture-benchmark"
20+
ReferencedContainer = "container:">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Release"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "swift-composable-architecture-benchmark"
48+
BuildableName = "swift-composable-architecture-benchmark"
49+
BlueprintName = "swift-composable-architecture-benchmark"
50+
ReferencedContainer = "container:">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<BuildableProductRunnable
61+
runnableDebuggingMode = "0">
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "swift-composable-architecture-benchmark"
65+
BuildableName = "swift-composable-architecture-benchmark"
66+
BlueprintName = "swift-composable-architecture-benchmark"
67+
ReferencedContainer = "container:">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1300"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "swift-composable-architecture-benchmarks"
18+
BuildableName = "swift-composable-architecture-benchmarks"
19+
BlueprintName = "swift-composable-architecture-benchmarks"
20+
ReferencedContainer = "container:">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Release"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "swift-composable-architecture-benchmarks"
48+
BuildableName = "swift-composable-architecture-benchmarks"
49+
BlueprintName = "swift-composable-architecture-benchmarks"
50+
ReferencedContainer = "container:">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<BuildableProductRunnable
61+
runnableDebuggingMode = "0">
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "swift-composable-architecture-benchmarks"
65+
BuildableName = "swift-composable-architecture-benchmarks"
66+
BlueprintName = "swift-composable-architecture-benchmarks"
67+
ReferencedContainer = "container:">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ test-examples:
4444
-scheme VoiceMemos \
4545
-destination platform="$(PLATFORM_IOS)"
4646

47+
benchmark:
48+
swift run --configuration release \
49+
swift-composable-architecture-benchmark
50+
4751
format:
4852
swift format --in-place --recursive \
4953
./Examples ./Package.swift ./Sources ./Tests

Package.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.1
1+
// swift-tools-version:5.2
22

33
import PackageDescription
44

@@ -14,9 +14,10 @@ let package = Package(
1414
.library(
1515
name: "ComposableArchitecture",
1616
targets: ["ComposableArchitecture"]
17-
)
17+
),
1818
],
1919
dependencies: [
20+
.package(name: "Benchmark", url: "https://github.com/google/swift-benchmark", from: "0.1.0"),
2021
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "0.4.0"),
2122
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "0.1.3"),
2223
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "0.1.0"),
@@ -25,16 +26,23 @@ let package = Package(
2526
.target(
2627
name: "ComposableArchitecture",
2728
dependencies: [
28-
"CasePaths",
29-
"CombineSchedulers",
30-
"XCTestDynamicOverlay",
29+
.product(name: "CasePaths", package: "swift-case-paths"),
30+
.product(name: "CombineSchedulers", package: "combine-schedulers"),
31+
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
3132
]
3233
),
3334
.testTarget(
3435
name: "ComposableArchitectureTests",
3536
dependencies: [
36-
"ComposableArchitecture"
37+
"ComposableArchitecture",
3738
]
3839
),
40+
.target(
41+
name: "swift-composable-architecture-benchmark",
42+
dependencies: [
43+
"ComposableArchitecture",
44+
.product(name: "Benchmark", package: "Benchmark"),
45+
]
46+
)
3947
]
4048
)

[email protected]

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// swift-tools-version:5.1
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "swift-composable-architecture",
7+
platforms: [
8+
.iOS(.v13),
9+
.macOS(.v10_15),
10+
.tvOS(.v13),
11+
.watchOS(.v6),
12+
],
13+
products: [
14+
.library(
15+
name: "ComposableArchitecture",
16+
targets: ["ComposableArchitecture"]
17+
)
18+
],
19+
dependencies: [
20+
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "0.4.0"),
21+
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "0.1.3"),
22+
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "0.1.0"),
23+
],
24+
targets: [
25+
.target(
26+
name: "ComposableArchitecture",
27+
dependencies: [
28+
"CasePaths",
29+
"CombineSchedulers",
30+
"XCTestDynamicOverlay",
31+
]
32+
),
33+
.testTarget(
34+
name: "ComposableArchitectureTests",
35+
dependencies: [
36+
"ComposableArchitecture"
37+
]
38+
),
39+
]
40+
)

Sources/ComposableArchitecture/SwiftUI/SwitchStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ public struct _ExhaustivityCheckView<State, Action>: View {
11841184
)
11851185
}
11861186
#else
1187-
EmptyView()
1187+
return EmptyView()
11881188
#endif
11891189
}
11901190
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import Benchmark
2+
import ComposableArchitecture
3+
4+
let counterReducer = Reducer<Int, Bool, Void> { state, action, _ in
5+
if action {
6+
state += 1
7+
} else {
8+
state = 0
9+
}
10+
return .none
11+
}
12+
13+
let store1 = Store(initialState: 0, reducer: counterReducer, environment: ())
14+
let store2 = store1.scope { $0 }
15+
let store3 = store2.scope { $0 }
16+
let store4 = store3.scope { $0 }
17+
18+
let viewStore1 = ViewStore(store1)
19+
let viewStore2 = ViewStore(store2)
20+
let viewStore3 = ViewStore(store3)
21+
let viewStore4 = ViewStore(store4)
22+
23+
benchmark("Scoping (1)") {
24+
viewStore1.send(true)
25+
}
26+
viewStore1.send(false)
27+
28+
benchmark("Scoping (2)") {
29+
viewStore2.send(true)
30+
}
31+
viewStore1.send(false)
32+
33+
benchmark("Scoping (3)") {
34+
viewStore3.send(true)
35+
}
36+
viewStore1.send(false)
37+
38+
benchmark("Scoping (4)") {
39+
viewStore4.send(true)
40+
}
41+
42+
Benchmark.main()

0 commit comments

Comments
 (0)