Skip to content

Commit 08e0ad6

Browse files
committed
[stdlib] Set, Dictionary: Enable per-instance hash seeds
The performance of operations merging two similar-sized sets or dictionaries is currently quadratic. Enabling per-instance seeds makes most of these linear, which is what most people expect. This affects Set.union, Set.symmetricDifference and similar operations, including the for-loop based forms that people write manually. The only remaining quadratic cases are when two sets/dictionaries are merged that are mutated copy-on-write copies of the same original instance. (We can’t change the hash seed without a full rehash,
1 parent 5e2c815 commit 08e0ad6

File tree

1 file changed

+0
-5
lines changed

1 file changed

+0
-5
lines changed

stdlib/public/core/HashTable.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ extension _HashTable {
9494
for object: AnyObject,
9595
scale: Int8
9696
) -> Int {
97-
#if false // FIXME: Enable per-instance seeding
9897
// We generate a new hash seed whenever a new hash table is allocated and
9998
// whenever an existing table is resized, so that we avoid certain copy
10099
// operations becoming quadratic. (For background details, see
@@ -115,10 +114,6 @@ extension _HashTable {
115114
// guarantee that no two tables with the same seed can coexist at the same
116115
// time (apart from copy-on-write derivatives of the same table).
117116
return unsafeBitCast(object, to: Int.self)
118-
#else
119-
// Use per-capacity seeding for now.
120-
return Int(scale)
121-
#endif
122117
}
123118
}
124119

0 commit comments

Comments
 (0)