Skip to content

Commit 82da037

Browse files
Suyash SrijanSuyash Srijan
authored andcommitted
Merge branch 'master' into fix/SR-7799
2 parents e8b5f1e + 4986105 commit 82da037

File tree

1,004 files changed

+31599
-10290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,004 files changed

+31599
-10290
lines changed

apinotes/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ add_custom_target("copy_apinotes"
2828
COMMENT "Copying API notes to ${output_dir}"
2929
SOURCES "${sources}")
3030

31+
# This is treated as an OPTIONAL target because if we don't build the SDK
32+
# overlay, the files will be missing anyway. It also allows us to build
33+
# single overlays without installing the API notes.
3134
swift_install_in_component(sdk-overlay
32-
FILES ${sources}
33-
DESTINATION "lib/swift/apinotes")
35+
DIRECTORY "${output_dir}"
36+
DESTINATION "lib/swift/"
37+
OPTIONAL)

benchmark/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ set(SWIFT_BENCH_MODULES
5858
single-source/ClassArrayGetter
5959
single-source/Codable
6060
single-source/Combos
61-
single-source/CountAlgo
6261
single-source/DataBenchmarks
6362
single-source/DeadArray
6463
single-source/DictOfArraysToArrayOfDicts
@@ -90,7 +89,6 @@ set(SWIFT_BENCH_MODULES
9089
single-source/FloatingPointPrinting
9190
single-source/Hanoi
9291
single-source/Hash
93-
single-source/HashQuadratic
9492
single-source/Histogram
9593
single-source/InsertCharacter
9694
single-source/Integrate

benchmark/Naming.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ benchmark is testing individual method on a concrete type.
2828
````
2929
⛔️ Dictionary2
3030
✅ AngryPhonebook
31-
✅ Dictionary.AnyHashable.String.update
3231
✅ Array.append.Array.Int
32+
✅ Dictionary.AnyHashable.String.update
3333
````
3434

3535
Benchmark names are used to run individual tests when passed as command line
@@ -42,8 +42,8 @@ optional chaining etc.
4242

4343
````
4444
✅ Array.append.Array.Int?
45-
✅ Flatten.Array.Tuple4.for-in.reserved
4645
✅ Bridging.NSArray.as!.Array.NSString
46+
✅ Flatten.Array.Tuple4.for-in.Reserve
4747
````
4848

4949
Note: Special characters that could be interpreted by the shell require escaping

benchmark/scripts/Benchmark_Driver

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class BenchmarkDriver(object):
200200
with open(log_file, 'w') as f:
201201
f.write(output)
202202

203-
RESULT = '{:>3} {:<25} {:>7} {:>7} {:>6} {:>10} {:>6} {:>7} {:>10}'
203+
RESULT = '{:>3} {:<40} {:>7} {:>7} {:>6} {:>10} {:>6} {:>7} {:>10}'
204204

205205
def run_and_log(self, csv_console=True):
206206
"""Run benchmarks and continuously log results to the console.

benchmark/scripts/compare_perf_tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ def _reset(self):
363363
# Parse lines like this
364364
# #,TEST,SAMPLES,MIN(μs),MAX(μs),MEAN(μs),SD(μs),MEDIAN(μs)
365365
results_re = re.compile(
366-
r'( *\d+[, \t]+[\w.]+[, \t]+' + # #,TEST
367-
r'[, \t]+'.join([r'\d+'] * 2) + # at least 2...
368-
r'(?:[, \t]+\d*)*)') # ...or more numeric columns
366+
r'( *\d+[, \t]+[\w.\-\?!]+[, \t]+' + # #,TEST
367+
r'[, \t]+'.join([r'\d+'] * 2) + # at least 2...
368+
r'(?:[, \t]+\d*)*)') # ...or more numeric columns
369369

370370
def _append_result(self, result):
371371
columns = result.split(',') if ',' in result else result.split()

benchmark/scripts/run_smoke_bench

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_performance(opt_level, old_dir, new_dir, threshold, num_samples,
185185
tests = TestComparator(results[0], results[1], threshold)
186186
changed = tests.decreased + tests.increased
187187

188-
while len(changed) > 0 and unchanged_length_count < 5:
188+
while len(changed) > 0 and unchanged_length_count < 10:
189189
i += 1
190190
if VERBOSE:
191191
log(' test again: ' + str([test.name for test in changed]))
@@ -205,25 +205,6 @@ def test_performance(opt_level, old_dir, new_dir, threshold, num_samples,
205205
threshold * 1.4, output_file, *results)
206206

207207

208-
def get_results(bench_dir, opt_level, num_samples, to_test):
209-
try:
210-
exe = os.path.join(bench_dir, 'bin', 'Benchmark_' + opt_level)
211-
args = [exe, '--num-samples=' + str(num_samples),
212-
'--sample-time=0.0025']
213-
if to_test:
214-
args += to_test
215-
env = {'DYLD_LIBRARY_PATH': os.path.join(bench_dir, 'lib', 'swift',
216-
'macos'),
217-
'SWIFT_DETERMINISTIC_HASHING': '1'}
218-
output = subprocess.check_output(args, env=env)
219-
except subprocess.CalledProcessError as e:
220-
sys.stderr.write(e.output)
221-
sys.stderr.flush()
222-
return sys.exit(e.returncode)
223-
else:
224-
return output
225-
226-
227208
def report_code_size(opt_level, old_dir, new_dir, platform, output_file):
228209
if opt_level == 'swiftlibs':
229210
files = glob.glob(os.path.join(old_dir, 'lib', 'swift', platform,

benchmark/scripts/test_Benchmark_Driver.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,10 @@ def mock_run(test):
366366
self.assertEqual(log, header + csv_log)
367367
self.assertEqual(
368368
out.getvalue(),
369-
' # TEST SAMPLES MIN(μs) Q1(μs)' +
370-
' MEDIAN(μs) Q3(μs) MAX(μs) MAX_RSS(B)\n' +
371-
' 3 b1 5 101 102' +
372-
' 103 104 105 888\n' +
369+
' # TEST SAMPLES MIN(μs)' +
370+
' Q1(μs) MEDIAN(μs) Q3(μs) MAX(μs) MAX_RSS(B)\n' +
371+
' 3 b1 5 101' +
372+
' 102 103 104 105 888\n' +
373373
'\n' +
374374
'Total performance tests executed: 1\n')
375375

benchmark/scripts/test_compare_perf_tests.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,20 @@ class TestLogParser(unittest.TestCase):
445445
def test_parse_results_csv(self):
446446
"""Ignores uknown lines, extracts data from supported formats."""
447447
log = """#,TEST,SAMPLES,MIN(us),MAX(us),MEAN(us),SD(us),MEDIAN(us)
448-
34,BitCount,20,3,4,4,0,4
448+
7,Array.append.Array.Int?,20,10,10,10,0,10
449+
21,Bridging.NSArray.as!.Array.NSString,20,11,11,11,0,11
450+
42,Flatten.Array.Tuple4.lazy.for-in.Reserve,20,3,4,4,0,4
449451
450452
Total performance tests executed: 1
451453
"""
452454
parser = LogParser()
453455
results = parser.parse_results(log.splitlines())
454456
self.assertTrue(isinstance(results[0], PerformanceTestResult))
455-
self.assertEqual(results[0].name, 'BitCount')
457+
self.assertEquals(results[0].name, 'Array.append.Array.Int?')
458+
self.assertEquals(results[1].name,
459+
'Bridging.NSArray.as!.Array.NSString')
460+
self.assertEquals(results[2].name,
461+
'Flatten.Array.Tuple4.lazy.for-in.Reserve')
456462

457463
def test_parse_results_tab_delimited(self):
458464
log = '34\tBitCount\t20\t3\t4\t4\t0\t4'

benchmark/single-source/ArrayInClass.swift

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import TestsUtils
14-
public let ArrayInClass = BenchmarkInfo(
15-
name: "ArrayInClass",
16-
runFunction: run_ArrayInClass,
17-
tags: [.validation, .api, .Array],
18-
setUpFunction: { ac = ArrayContainer() },
19-
tearDownFunction: { ac = nil })
14+
public let ArrayInClass = [
15+
BenchmarkInfo(
16+
name: "ArrayInClass",
17+
runFunction: run_ArrayInClass,
18+
tags: [.validation, .api, .Array],
19+
setUpFunction: { ac = ArrayContainer() },
20+
tearDownFunction: { ac = nil }),
21+
BenchmarkInfo(name: "DistinctClassFieldAccesses",
22+
runFunction: run_DistinctClassFieldAccesses,
23+
tags: [.unstable, .api, .Array],
24+
setUpFunction: { workload = ClassWithArrs(N: 100_000) },
25+
tearDownFunction: { workload = nil }),
26+
]
2027

2128
var ac: ArrayContainer!
2229

@@ -41,3 +48,38 @@ public func run_ArrayInClass(_ N: Int) {
4148
let a = ac!
4249
a.runLoop(N)
4350
}
51+
52+
class ClassWithArrs {
53+
var N: Int = 0
54+
var A: [Int]
55+
var B: [Int]
56+
57+
init(N: Int) {
58+
self.N = N
59+
60+
A = [Int](repeating: 0, count: N)
61+
B = [Int](repeating: 0, count: N)
62+
}
63+
64+
func readArr() {
65+
for i in 0..<self.N {
66+
guard A[i] == B[i] else { fatalError("") }
67+
}
68+
}
69+
70+
func writeArr() {
71+
for i in 0..<self.N {
72+
A[i] = i
73+
B[i] = i
74+
}
75+
}
76+
}
77+
78+
var workload: ClassWithArrs!
79+
80+
public func run_DistinctClassFieldAccesses(_ N: Int) {
81+
for _ in 1...N {
82+
workload.writeArr()
83+
workload.readArr()
84+
}
85+
}

benchmark/single-source/ArrayLiteral.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import TestsUtils
1717

1818
public let ArrayLiteral = [
19-
BenchmarkInfo(name: "ArrayLiteral", runFunction: run_ArrayLiteral, tags: [.validation, .api, .Array]),
19+
BenchmarkInfo(name: "ArrayLiteral2", runFunction: run_ArrayLiteral, tags: [.validation, .api, .Array]),
2020
BenchmarkInfo(name: "ArrayValueProp", runFunction: run_ArrayValueProp, tags: [.validation, .api, .Array]),
2121
BenchmarkInfo(name: "ArrayValueProp2", runFunction: run_ArrayValueProp2, tags: [.validation, .api, .Array]),
2222
BenchmarkInfo(name: "ArrayValueProp3", runFunction: run_ArrayValueProp3, tags: [.validation, .api, .Array]),
@@ -31,7 +31,7 @@ func makeArray() -> [Int] {
3131
@inline(never)
3232
public func run_ArrayLiteral(_ N: Int) {
3333
for _ in 1...10000*N {
34-
_ = makeArray()
34+
blackHole(makeArray())
3535
}
3636
}
3737

benchmark/single-source/ArrayOfGenericPOD.swift

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,21 @@
2020

2121
import TestsUtils
2222

23-
public let ArrayOfGenericPOD = BenchmarkInfo(
24-
// Renamed benchmark to "2" when IUO test was removed, which
25-
// effectively changed what we're benchmarking here.
26-
name: "ArrayOfGenericPOD2",
27-
runFunction: run_ArrayOfGenericPOD,
28-
tags: [.validation, .api, .Array])
23+
public let ArrayOfGenericPOD = [
24+
BenchmarkInfo(
25+
// Renamed benchmark to "2" when IUO test was removed, which
26+
// effectively changed what we're benchmarking here.
27+
name: "ArrayOfGenericPOD2",
28+
runFunction: run_ArrayOfGenericPOD,
29+
tags: [.validation, .api, .Array]),
30+
31+
// Initialize an array of generic POD from a slice.
32+
// This takes a unique path through stdlib customization points.
33+
BenchmarkInfo(
34+
name: "ArrayInitFromSlice",
35+
runFunction: run_initFromSlice,
36+
tags: [.validation, .api, .Array], setUpFunction: createArrayOfPOD)
37+
]
2938

3039
class RefArray<T> {
3140
var array: [T]
@@ -64,3 +73,29 @@ public func run_ArrayOfGenericPOD(_ N: Int) {
6473
genStructArray()
6574
}
6675
}
76+
77+
// --- ArrayInitFromSlice
78+
79+
var globalArray = Array<UInt8>(repeating: 0, count: 4096)
80+
81+
func createArrayOfPOD() {
82+
blackHole(globalArray)
83+
}
84+
85+
@inline(never)
86+
@_optimize(none)
87+
func copyElements<S: Sequence>(_ contents: S) -> [UInt8]
88+
where S.Iterator.Element == UInt8
89+
{
90+
return [UInt8](contents)
91+
}
92+
93+
@inline(never)
94+
public func run_initFromSlice(_ N: Int) {
95+
for _ in 0..<N {
96+
for _ in 0..<1000 {
97+
// Slice off at least one element so the array buffer can't be reused.
98+
blackHole(copyElements(globalArray[0..<4095]))
99+
}
100+
}
101+
}

benchmark/single-source/ArraySetElement.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import TestsUtils
1818
public var ArraySetElement = BenchmarkInfo(
1919
name: "ArraySetElement",
2020
runFunction: run_ArraySetElement,
21-
tags: [.runtime, .cpubench, .unstable],
22-
legacyFactor: 10
21+
tags: [.runtime, .cpubench]
2322
)
2423

2524
// This is an effort to defeat isUniquelyReferenced optimization. Ideally
@@ -31,7 +30,7 @@ func storeArrayElement(_ array: inout [Int], _ i: Int) {
3130

3231
public func run_ArraySetElement(_ N: Int) {
3332
var array = [Int](repeating: 0, count: 10000)
34-
for _ in 0..<N {
33+
for _ in 0..<10*N {
3534
for i in 0..<array.count {
3635
storeArrayElement(&array, i)
3736
}

benchmark/single-source/Codable.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,6 @@ 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-
122110
@inline(never)
123111
public func run_JSONPerfEncode(_ N: Int) {
124112
autoreleasepool {

0 commit comments

Comments
 (0)