Skip to content

Commit b34f9f8

Browse files
authored
Merge pull request #21905 from gottesmm/pr-e4aa69192289f84c89c0ffdec8febf6e15f0558f
[benchmark] Add autoreleasepools to the Codable tests to prevent "lea…
2 parents ef85f63 + 9911d0a commit b34f9f8

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

benchmark/single-source/Codable.swift

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,33 @@ public func setup_json() {
107107
JSONTester = CodablePerfTester(encoder: JSONEncoder(), decoder: JSONDecoder())
108108
}
109109

110+
#if !_runtime(_ObjC)
111+
// If we do not have an objc-runtime, then we do not have a definition for
112+
// autoreleasepool. Add in our own fake autoclosure for it that is inline
113+
// always. That should be able to be eaten through by the optimizer no problem.
114+
@inline(__always)
115+
public func autoreleasepool<Result>(
116+
invoking body: () throws -> Result
117+
) rethrows -> Result {
118+
return try body()
119+
}
120+
#endif
121+
110122
@inline(never)
111123
public func run_JSONPerfEncode(_ N: Int) {
112-
for _ in 0 ..< N {
113-
JSONTester.encode()
124+
autoreleasepool {
125+
for _ in 0 ..< N {
126+
JSONTester.encode()
127+
}
114128
}
115129
}
116130

117131
@inline(never)
118132
public func run_JSONPerfDecode(_ N: Int) {
119-
for _ in 0 ..< N {
120-
JSONTester.decode()
133+
autoreleasepool {
134+
for _ in 0 ..< N {
135+
JSONTester.decode()
136+
}
121137
}
122138
}
123139

@@ -131,15 +147,19 @@ public func setup_plist() {
131147

132148
@inline(never)
133149
public func run_PlistPerfEncode(_ N: Int) {
134-
for _ in 0 ..< N {
135-
plistTester.encode()
150+
autoreleasepool {
151+
for _ in 0 ..< N {
152+
plistTester.encode()
153+
}
136154
}
137155
}
138156

139157
@inline(never)
140158
public func run_PlistPerfDecode(_ N: Int) {
141-
for _ in 0 ..< N {
142-
plistTester.decode()
159+
autoreleasepool {
160+
for _ in 0 ..< N {
161+
plistTester.decode()
162+
}
143163
}
144164
}
145165

0 commit comments

Comments
 (0)