Skip to content

Commit e76bdf8

Browse files
ptoffygwynne
andauthored
V5 (#141)
* Change comma * Fix benchmarks take two (#140) * Fix benchmarks take two * Add throughput thresholds * Wip * Make `Router` Swift 6 ready (#135) * First attempt at Swift 6 router * Make router immutable in benchmarks * Update benchmarks manifest * Re-add swift settings * Make options immutable * Update thresholds * Update thresholds * Update benchmarks * Adjust thresholds * Adjust thresholds * Use appropriate property * Create RouterBuilder * Update benchmarks * Address review and sprinke some `@inlinable` * Add back package setting * Update benchmarks * Update benchmark thresholds * Adjust threshold * Implement partial matching of routes (#142) * Implement partial matching * Attempt at making it fast * Cleanup * Undo * Partial Matching 2 (#143) * Different approach to partial matching * Nits * Avoid a copy * Minor improvements * Nit * Update Sources/RoutingKit/PathComponent.swift Co-authored-by: Gwynne Raskind <gwynne@vapor.codes> * Update Sources/RoutingKit/TrieRouter/TrieRouterNode.swift Co-authored-by: Gwynne Raskind <gwynne@vapor.codes> * Nits * Nit --------- Co-authored-by: Gwynne Raskind <gwynne@vapor.codes> * Add some docs * Address review and add specificity sorting * Add specificity comment * Add precondition failure for invalid partial * Don't run 6.2 test syntax on <6.2 * Nits * Apply suggestions from code review Co-authored-by: Gwynne Raskind <gwynne@vapor.codes> * Don't run exit test on Android --------- Co-authored-by: Gwynne Raskind <gwynne@vapor.codes>
1 parent 1a10cce commit e76bdf8

22 files changed

Lines changed: 952 additions & 572 deletions

Benchmarks/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PackageDescription
44
let package = Package(
55
name: "benchmarks",
66
platforms: [
7-
.macOS(.v13)
7+
.macOS(.v15)
88
],
99
dependencies: [
1010
.package(path: "../"),

Benchmarks/RouterPerformance/RouterPerformance.swift renamed to Benchmarks/RouterPerformance/TrieRouterPerformance.swift

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,119 +3,146 @@ import RoutingKit
33

44
let benchmarks = { @Sendable () -> Void in
55
Benchmark.defaultConfiguration = .init(
6-
metrics: [.mallocCountTotal, .peakMemoryResident, .throughput]
6+
metrics: [.mallocCountTotal, .peakMemoryResident, .throughput],
7+
thresholds: [
8+
.mallocCountTotal: .init(
9+
relative: [.p90: 1],
10+
absolute: [.p90: 2]
11+
),
12+
.peakMemoryResident: .init(
13+
relative: [.p90: 5],
14+
absolute: [.p90: 1_000_000]
15+
),
16+
.throughput: .init(
17+
relative: [.p90: 10]
18+
),
19+
]
720
)
821

922
Benchmark("Case-sensitive") { benchmark in
10-
let router = TrieRouter(String.self)
23+
var builder = TrieRouterBuilder(String.self)
1124
for letter in ["a", "b", "c", "d", "e", "f", "g"] {
12-
router.register(
25+
builder.register(
1326
letter,
1427
at: [
1528
.constant(letter),
1629
.parameter("\(letter)_id"),
1730
])
1831
}
1932

33+
let router = builder.build()
34+
benchmark.startMeasurement()
2035
for _ in benchmark.scaledIterations {
2136
var params = Parameters()
2237
_ = router.route(path: ["a", "42"], parameters: &params)
2338
}
2439
}
2540

2641
Benchmark("Case-insensitive") { benchmark in
27-
let router = TrieRouter.init(String.self, options: [.caseInsensitive])
42+
var builder = TrieRouterBuilder(String.self, options: [.caseInsensitive])
2843
for letter in ["a", "b", "c", "d", "e", "f", "g"] {
29-
router.register(
44+
builder.register(
3045
letter,
3146
at: [
3247
.constant(letter),
3348
.parameter("\(letter)_id"),
3449
])
3550
}
3651

52+
let router = builder.build()
53+
benchmark.startMeasurement()
3754
for _ in benchmark.scaledIterations {
3855
var params = Parameters()
3956
_ = router.route(path: ["a", "42"], parameters: &params)
4057
}
4158
}
4259

43-
Benchmark("Case-insensitive Match First") { benchmark in
44-
let router = TrieRouter.init(String.self, options: [.caseInsensitive])
60+
Benchmark("Case-insensitive_Match_First") { benchmark in
61+
var builder = TrieRouterBuilder(String.self, options: [.caseInsensitive])
4562
for letter in ["aaaaaaaa", "aaaaaaab", "aaaaaaac", "aaaaaaad", "aaaaaaae", "aaaaaaaf", "aaaaaaag"] {
46-
router.register(
63+
builder.register(
4764
letter,
4865
at: [
4966
.constant(letter),
5067
.parameter("\(letter)_id"),
5168
])
5269
}
5370

71+
let router = builder.build()
72+
benchmark.startMeasurement()
5473
for _ in benchmark.scaledIterations {
5574
var params = Parameters()
5675
_ = router.route(path: ["aaaaaaaa", "42"], parameters: &params)
5776
}
5877
}
5978

60-
Benchmark("Case-insensitive Match Last") { benchmark in
61-
let router = TrieRouter.init(String.self, options: [.caseInsensitive])
79+
Benchmark("Case-insensitive_Match_Last") { benchmark in
80+
var builder = TrieRouterBuilder(String.self, options: [.caseInsensitive])
6281
for letter in ["aaaaaaaa", "aaaaaaab", "aaaaaaac", "aaaaaaad", "aaaaaaae", "aaaaaaaf", "aaaaaaag"] {
63-
router.register(
82+
builder.register(
6483
letter,
6584
at: [
6685
.constant(letter),
6786
.parameter("\(letter)_id"),
6887
])
6988
}
7089

90+
let router = builder.build()
91+
benchmark.startMeasurement()
7192
for _ in benchmark.scaledIterations {
7293
var params = Parameters()
7394
_ = router.route(path: ["aaaaaaag", "42"], parameters: &params)
7495
}
7596
}
7697

77-
Benchmark("Case-sensitive Minimal") { benchmark in
78-
let router = TrieRouter.init(String.self)
98+
Benchmark("Case-sensitive_Minimal") { benchmark in
99+
var builder = TrieRouterBuilder(String.self)
79100
for letter in ["a"] {
80-
router.register(
101+
builder.register(
81102
letter,
82103
at: [
83104
.constant(letter)
84105
])
85106
}
86107

108+
let router = builder.build()
109+
benchmark.startMeasurement()
87110
for _ in benchmark.scaledIterations {
88111
var params = Parameters()
89112
_ = router.route(path: ["a"], parameters: &params)
90113
}
91114
}
92115

93-
Benchmark("Case-insensitive Minimal") { benchmark in
94-
let router = TrieRouter.init(String.self, options: [.caseInsensitive])
116+
Benchmark("Case-insensitive_Minimal") { benchmark in
117+
var builder = TrieRouterBuilder(String.self, options: [.caseInsensitive])
95118
for letter in ["a"] {
96-
router.register(
119+
builder.register(
97120
letter,
98121
at: [
99122
.constant(letter)
100123
])
101124
}
102125

126+
let router = builder.build()
127+
benchmark.startMeasurement()
103128
for _ in benchmark.scaledIterations {
104129
var params = Parameters()
105130
_ = router.route(path: ["a"], parameters: &params)
106131
}
107132
}
108133

109-
Benchmark("Minimal Early Fail") { benchmark in
110-
let router = TrieRouter.init(String.self)
134+
Benchmark("Minimal_Early_Fail") { benchmark in
135+
var builder = TrieRouterBuilder(String.self)
111136
for letter in ["aaaaaaaaaaaaaa"] {
112-
router.register(
137+
builder.register(
113138
letter,
114139
at: [
115140
.constant(letter)
116141
])
117142
}
118143

144+
let router = builder.build()
145+
benchmark.startMeasurement()
119146
for _ in benchmark.scaledIterations {
120147
var params = Parameters()
121148
_ = router.route(path: ["baaaaaaaaaaaaa"], parameters: &params)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"mallocCountTotal": 58,
3-
"peakMemoryResident": 24000000,
4-
"throughput": 67
2+
"mallocCountTotal": 22,
3+
"peakMemoryResident": 23000000,
4+
"throughput": 194000
55
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"mallocCountTotal": 58,
3-
"peakMemoryResident": 24000000,
4-
"throughput": 68
2+
"mallocCountTotal": 22,
3+
"peakMemoryResident": 23000000,
4+
"throughput": 194000
55
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"mallocCountTotal": 58,
3-
"peakMemoryResident": 24000000,
4-
"throughput": 69
2+
"mallocCountTotal": 22,
3+
"peakMemoryResident": 23000000,
4+
"throughput": 184000
55
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"mallocCountTotal": 24,
3-
"peakMemoryResident": 23000000,
4-
"throughput": 254
2+
"mallocCountTotal": 18,
3+
"peakMemoryResident": 24000000,
4+
"throughput": 493000
55
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"mallocCountTotal": 57,
3-
"peakMemoryResident": 24000000,
4-
"throughput": 71
2+
"mallocCountTotal": 22,
3+
"peakMemoryResident": 23000000,
4+
"throughput": 196000
55
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"mallocCountTotal": 23,
2+
"mallocCountTotal": 18,
33
"peakMemoryResident": 23000000,
4-
"throughput": 263
4+
"throughput": 501000
55
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"mallocCountTotal": 23,
2+
"mallocCountTotal": 18,
33
"peakMemoryResident": 23000000,
4-
"throughput": 267
4+
"throughput": 512000
55
}

Package.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
// swift-tools-version:5.10
1+
// swift-tools-version:6.1
22
import PackageDescription
33

44
let package = Package(
55
name: "routing-kit",
66
platforms: [
7-
.macOS(.v10_15),
8-
.iOS(.v13),
9-
.tvOS(.v13),
10-
.watchOS(.v6),
7+
.macOS(.v15),
8+
.iOS(.v18),
9+
.tvOS(.v18),
10+
.watchOS(.v11),
1111
],
1212
products: [
1313
.library(name: "RoutingKit", targets: ["RoutingKit"])
1414
],
1515
dependencies: [
16-
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.3")
16+
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.4"),
17+
.package(url: "https://github.com/apple/swift-algorithms.git", from: "1.2.1"),
1718
],
1819
targets: [
1920
.target(
2021
name: "RoutingKit",
2122
dependencies: [
22-
.product(name: "Logging", package: "swift-log")
23+
.product(name: "Logging", package: "swift-log"),
24+
.product(name: "Algorithms", package: "swift-algorithms"),
2325
],
2426
swiftSettings: swiftSettings
2527
),
@@ -37,6 +39,9 @@ var swiftSettings: [SwiftSetting] {
3739
[
3840
.enableUpcomingFeature("ExistentialAny"),
3941
.enableUpcomingFeature("MemberImportVisibility"),
40-
.enableExperimentalFeature("StrictConcurrency=complete"),
42+
.enableUpcomingFeature("InternalImportsByDefault"),
43+
.enableUpcomingFeature("InferIsolatedConformances"),
44+
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
45+
.enableUpcomingFeature("ImmutableWeakCaptures"),
4146
]
4247
}

0 commit comments

Comments
 (0)