Skip to content

Commit f5ba89d

Browse files
authored
Merge pull request #24513 from palimondo/fix-existential-perf-setup-overhead
[benchmark] Fix Existential.Array.Mutating Setup Overhead
2 parents b16ee94 + cdc47f6 commit f5ba89d

File tree

2 files changed

+9
-31
lines changed

2 files changed

+9
-31
lines changed

benchmark/single-source/ExistentialPerformance.swift

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,6 @@ func caRef1() { ca(Ref1.self) }
264264
func caRef2() { ca(Ref2.self) }
265265
func caRef3() { ca(Ref3.self) }
266266
func caRef4() { ca(Ref4.self) }
267-
@inline(never)
268-
func grabArray() -> [Existential] { // transfer array ownership to caller
269-
// FIXME: This is causing Illegal Instruction: 4 crash
270-
// defer { array = nil }
271-
// return array
272-
// This doesn't work either:
273-
// let a = array!
274-
// array = nil
275-
// return a
276-
return array!
277-
}
278267

279268
// `setUpFunctions` that determine which existential type will be tested
280269
var existentialType: Existential.Type!
@@ -540,7 +529,7 @@ func run_Array_init(_ N: Int) {
540529
}
541530

542531
func run_Array_method1x(_ N: Int) {
543-
let existentialArray = grabArray()
532+
let existentialArray = array!
544533
for _ in 0 ..< N * 100 {
545534
for elt in existentialArray {
546535
if !elt.doIt() {
@@ -551,7 +540,7 @@ func run_Array_method1x(_ N: Int) {
551540
}
552541

553542
func run_Array_method2x(_ N: Int) {
554-
let existentialArray = grabArray()
543+
let existentialArray = array!
555544
for _ in 0 ..< N * 100 {
556545
for elt in existentialArray {
557546
if !elt.doIt() || !elt.reallyDoIt() {
@@ -562,8 +551,8 @@ func run_Array_method2x(_ N: Int) {
562551
}
563552

564553
func run_ArrayMutating(_ N: Int) {
565-
var existentialArray = grabArray()
566-
for _ in 0 ..< N * 100 {
554+
var existentialArray = array!
555+
for _ in 0 ..< N * 500 {
567556
for i in 0 ..< existentialArray.count {
568557
if !existentialArray[i].mutateIt() {
569558
fatalError("expected true")
@@ -573,7 +562,7 @@ func run_ArrayMutating(_ N: Int) {
573562
}
574563

575564
func run_ArrayShift(_ N: Int) {
576-
var existentialArray = grabArray()
565+
var existentialArray = array!
577566
for _ in 0 ..< N * 25 {
578567
for i in 0 ..< existentialArray.count-1 {
579568
existentialArray.swapAt(i, i+1)
@@ -582,7 +571,7 @@ func run_ArrayShift(_ N: Int) {
582571
}
583572

584573
func run_ArrayConditionalShift(_ N: Int) {
585-
var existentialArray = grabArray()
574+
var existentialArray = array!
586575
for _ in 0 ..< N * 25 {
587576
for i in 0 ..< existentialArray.count-1 {
588577
let curr = existentialArray[i]

benchmark/single-source/ExistentialPerformance.swift.gyb

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ Setup = """
3636
let existential = existentialType.init()
3737
let existential2 = existentialType.init()
3838
var existential = existentialType.init()
39-
let existentialArray = grabArray()
40-
var existentialArray = grabArray()
39+
let existentialArray = array!
40+
var existentialArray = array!
4141
""".splitlines()
4242
Setup = [Setup[0], Setup[1], '\n'.join(Setup[1:3]), Setup[3], Setup[4], Setup[5]]
4343

@@ -90,7 +90,7 @@ Workloads = [
9090
}
9191
}
9292
"""),
93-
('Array.Mutating', Setup[5], '100', """
93+
('Array.Mutating', Setup[5], '500', """
9494
for i in 0 ..< existentialArray.count {
9595
if !existentialArray[i].mutateIt() {
9696
fatalError("expected true")
@@ -151,17 +151,6 @@ func ca<T: Existential>(_: T.Type) {
151151
% for Variant in Vals + Refs:
152152
func ca${Variant}() { ca(${Variant}.self) }
153153
% end
154-
@inline(never)
155-
func grabArray() -> [Existential] { // transfer array ownership to caller
156-
// FIXME: This is causing Illegal Instruction: 4 crash
157-
// defer { array = nil }
158-
// return array
159-
// This doesn't work either:
160-
// let a = array!
161-
// array = nil
162-
// return a
163-
return array!
164-
}
165154

166155
// `setUpFunctions` that determine which existential type will be tested
167156
var existentialType: Existential.Type!

0 commit comments

Comments
 (0)