Skip to content

Commit 29ad714

Browse files
committed
Annotate stdlib functions to get a good performance even in resilient mode, when -sil-serialize-all is disabled
This commit mostly improves the performance of arrays and ranges. It does not cover Strings, Dictionaries and Sets yet.
1 parent a8e4e72 commit 29ad714

Some content is hidden

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

47 files changed

+1294
-11
lines changed

benchmark/single-source/PopFrontGeneric.swift

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ let arrayCount = 1024
1717

1818
// This test case exposes rdar://17440222 which caused rdar://17974483 (popFront
1919
// being really slow).
20+
@_versioned
2021
protocol MyArrayBufferProtocol : MutableCollection, RandomAccessCollection {
2122
associatedtype Element
2223

stdlib/private/StdlibUnittestFoundationExtras/StdlibUnittestFoundationExtras.swift

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public func autoreleasepoolIfUnoptimizedReturnAutoreleased(
7575
#endif
7676
}
7777

78+
@_versioned
7879
@_silgen_name("swift_stdlib_NSArray_getObjects")
7980
internal func _stdlib_NSArray_getObjects(
8081
nsArray: AnyObject,

stdlib/public/core/Algorithm.swift

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/// - x: A value to compare.
1717
/// - y: Another value to compare.
1818
/// - Returns: The lesser of `x` and `y`. If `x` is equal to `y`, returns `x`.
19+
@_inlineable
1920
public func min<T : Comparable>(_ x: T, _ y: T) -> T {
2021
// In case `x == y` we pick `x`.
2122
// This preserves any pre-existing order in case `T` has identity,
@@ -33,6 +34,7 @@ public func min<T : Comparable>(_ x: T, _ y: T) -> T {
3334
/// - rest: Zero or more additional values.
3435
/// - Returns: The least of all the arguments. If there are multiple equal
3536
/// least arguments, the result is the first one.
37+
@_inlineable
3638
public func min<T : Comparable>(_ x: T, _ y: T, _ z: T, _ rest: T...) -> T {
3739
var minValue = min(min(x, y), z)
3840
// In case `value == minValue`, we pick `minValue`. See min(_:_:).
@@ -48,6 +50,7 @@ public func min<T : Comparable>(_ x: T, _ y: T, _ z: T, _ rest: T...) -> T {
4850
/// - x: A value to compare.
4951
/// - y: Another value to compare.
5052
/// - Returns: The greater of `x` and `y`. If `x` is equal to `y`, returns `y`.
53+
@_inlineable
5154
public func max<T : Comparable>(_ x: T, _ y: T) -> T {
5255
// In case `x == y`, we pick `y`. See min(_:_:).
5356
return y >= x ? y : x
@@ -62,6 +65,7 @@ public func max<T : Comparable>(_ x: T, _ y: T) -> T {
6265
/// - rest: Zero or more additional values.
6366
/// - Returns: The greatest of all the arguments. If there are multiple equal
6467
/// greatest arguments, the result is the last one.
68+
@_inlineable
6569
public func max<T : Comparable>(_ x: T, _ y: T, _ z: T, _ rest: T...) -> T {
6670
var maxValue = max(max(x, y), z)
6771
// In case `value == maxValue`, we pick `value`. See min(_:_:).
@@ -85,13 +89,18 @@ public func max<T : Comparable>(_ x: T, _ y: T, _ z: T, _ rest: T...) -> T {
8589
///
8690
/// To create an instance of `EnumeratedIterator`, call
8791
/// `enumerated().makeIterator()` on a sequence or collection.
92+
@_fixed_layout
8893
public struct EnumeratedIterator<
8994
Base : IteratorProtocol
9095
> : IteratorProtocol, Sequence {
96+
@_versioned
9197
internal var _base: Base
98+
@_versioned
9299
internal var _count: Int
93100

94101
/// Construct from a `Base` iterator.
102+
@_inlineable
103+
@_versioned
95104
internal init(_base: Base) {
96105
self._base = _base
97106
self._count = 0
@@ -104,6 +113,7 @@ public struct EnumeratedIterator<
104113
/// exists.
105114
///
106115
/// Once `nil` has been returned, all subsequent calls return `nil`.
116+
@_inlineable
107117
public mutating func next() -> Element? {
108118
guard let b = _base.next() else { return nil }
109119
let result = (offset: _count, element: b)
@@ -128,15 +138,20 @@ public struct EnumeratedIterator<
128138
/// }
129139
/// // Prints "0: foo"
130140
/// // Prints "1: bar"
141+
@_fixed_layout
131142
public struct EnumeratedSequence<Base : Sequence> : Sequence {
143+
@_versioned
132144
internal var _base: Base
133145

134146
/// Construct from a `Base` sequence.
147+
@_inlineable
148+
@_versioned
135149
internal init(_base: Base) {
136150
self._base = _base
137151
}
138152

139153
/// Returns an iterator over the elements of this sequence.
154+
@_inlineable
140155
public func makeIterator() -> EnumeratedIterator<Base.Iterator> {
141156
return EnumeratedIterator(_base: _base.makeIterator())
142157
}

stdlib/public/core/ArrayBody.swift

+13
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717

1818
import SwiftShims
1919

20+
@_fixed_layout
2021
@_versioned
2122
internal struct _ArrayBody {
23+
@_versioned
2224
var _storage: _SwiftArrayBodyStorage
2325

26+
@_inlineable
2427
@_versioned
2528
init(count: Int, capacity: Int, elementTypeIsBridgedVerbatim: Bool = false) {
2629
_sanityCheck(count >= 0)
@@ -36,11 +39,15 @@ internal struct _ArrayBody {
3639
/// constructed, but since we want to claim all the allocated
3740
/// capacity after a new buffer is allocated, it's typical to want
3841
/// to update it immediately after construction.
42+
@_inlineable
43+
@_versioned
3944
init() {
4045
_storage = _SwiftArrayBodyStorage(count: 0, _capacityAndFlags: 0)
4146
}
4247

4348
/// The number of elements stored in this Array.
49+
@_inlineable
50+
@_versioned
4451
var count: Int {
4552
get {
4653
return _assumeNonNegative(_storage.count)
@@ -52,6 +59,8 @@ internal struct _ArrayBody {
5259

5360
/// The number of elements that can be stored in this Array without
5461
/// reallocation.
62+
@_inlineable
63+
@_versioned
5564
var capacity: Int {
5665
return Int(_capacityAndFlags >> 1)
5766
}
@@ -62,6 +71,8 @@ internal struct _ArrayBody {
6271
/// optimizer before 1.0 ships, so we store it in a bit here to
6372
/// avoid the cost of calls into the runtime that compute the
6473
/// answer.
74+
@_inlineable
75+
@_versioned
6576
var elementTypeIsBridgedVerbatim: Bool {
6677
get {
6778
return (_capacityAndFlags & 0x1) != 0
@@ -74,6 +85,8 @@ internal struct _ArrayBody {
7485

7586
/// Storage optimization: compresses capacity and
7687
/// elementTypeIsBridgedVerbatim together.
88+
@_inlineable
89+
@_versioned
7790
var _capacityAndFlags: UInt {
7891
get {
7992
return _storage._capacityAndFlags

0 commit comments

Comments
 (0)