Skip to content

[benchmark] Fix Existential.Array.Mutating Setup Overhead #24513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions benchmark/single-source/ExistentialPerformance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,6 @@ func caRef1() { ca(Ref1.self) }
func caRef2() { ca(Ref2.self) }
func caRef3() { ca(Ref3.self) }
func caRef4() { ca(Ref4.self) }
@inline(never)
func grabArray() -> [Existential] { // transfer array ownership to caller
// FIXME: This is causing Illegal Instruction: 4 crash
// defer { array = nil }
// return array
// This doesn't work either:
// let a = array!
// array = nil
// return a
return array!
}

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

func run_Array_method1x(_ N: Int) {
let existentialArray = grabArray()
let existentialArray = array!
for _ in 0 ..< N * 100 {
for elt in existentialArray {
if !elt.doIt() {
Expand All @@ -551,7 +540,7 @@ func run_Array_method1x(_ N: Int) {
}

func run_Array_method2x(_ N: Int) {
let existentialArray = grabArray()
let existentialArray = array!
for _ in 0 ..< N * 100 {
for elt in existentialArray {
if !elt.doIt() || !elt.reallyDoIt() {
Expand All @@ -562,8 +551,8 @@ func run_Array_method2x(_ N: Int) {
}

func run_ArrayMutating(_ N: Int) {
var existentialArray = grabArray()
for _ in 0 ..< N * 100 {
var existentialArray = array!
for _ in 0 ..< N * 500 {
for i in 0 ..< existentialArray.count {
if !existentialArray[i].mutateIt() {
fatalError("expected true")
Expand All @@ -573,7 +562,7 @@ func run_ArrayMutating(_ N: Int) {
}

func run_ArrayShift(_ N: Int) {
var existentialArray = grabArray()
var existentialArray = array!
for _ in 0 ..< N * 25 {
for i in 0 ..< existentialArray.count-1 {
existentialArray.swapAt(i, i+1)
Expand All @@ -582,7 +571,7 @@ func run_ArrayShift(_ N: Int) {
}

func run_ArrayConditionalShift(_ N: Int) {
var existentialArray = grabArray()
var existentialArray = array!
for _ in 0 ..< N * 25 {
for i in 0 ..< existentialArray.count-1 {
let curr = existentialArray[i]
Expand Down
17 changes: 3 additions & 14 deletions benchmark/single-source/ExistentialPerformance.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Setup = """
let existential = existentialType.init()
let existential2 = existentialType.init()
var existential = existentialType.init()
let existentialArray = grabArray()
var existentialArray = grabArray()
let existentialArray = array!
var existentialArray = array!
""".splitlines()
Setup = [Setup[0], Setup[1], '\n'.join(Setup[1:3]), Setup[3], Setup[4], Setup[5]]

Expand Down Expand Up @@ -90,7 +90,7 @@ Workloads = [
}
}
"""),
('Array.Mutating', Setup[5], '100', """
('Array.Mutating', Setup[5], '500', """
for i in 0 ..< existentialArray.count {
if !existentialArray[i].mutateIt() {
fatalError("expected true")
Expand Down Expand Up @@ -151,17 +151,6 @@ func ca<T: Existential>(_: T.Type) {
% for Variant in Vals + Refs:
func ca${Variant}() { ca(${Variant}.self) }
% end
@inline(never)
func grabArray() -> [Existential] { // transfer array ownership to caller
// FIXME: This is causing Illegal Instruction: 4 crash
// defer { array = nil }
// return array
// This doesn't work either:
// let a = array!
// array = nil
// return a
return array!
}

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