Skip to content

Commit 2aec2d5

Browse files
committed
[DynamicArray] Reduce growth factor to 1.5
1 parent 39dc431 commit 2aec2d5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sources/ArrayModule/DynamicArray.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ extension DynamicArray where Element: ~Copyable {
261261
@_alwaysEmitIntoClient
262262
@_transparent
263263
internal func _growDynamicArrayCapacity(_ capacity: Int) -> Int {
264-
2 * capacity
264+
// A growth factor of 1.5 seems like a reasonable compromise between
265+
// over-allocating memory and wasting cycles on repeatedly resizing storage.
266+
3 * capacity / 2
265267
}
266268

267269
extension DynamicArray where Element: ~Copyable {

0 commit comments

Comments
 (0)