Commit Graph

20 Commits

Author SHA1 Message Date
Karoy Lorentey
db80c78809 [stdlib] Optimize Set.filter(_:)
This works the same way as `Set.subtracting<S>(_:)`, and has similar performance benefits.
2021-11-01 21:38:10 -07:00
Karoy Lorentey
80296bb606 [stdlib] Optimize Set.subtracting(_:)
Use a temporary bitset to avoid hashing elements more than once, and to prevent rehashings during the creation of the result set.

This leads to a speedup of about 0-4x, depending on the number of elements removed.
2021-11-01 21:38:10 -07:00
Ben Cohen
e9d4687e31 De-underscore @frozen, apply it to structs (#24185)
* De-underscore @frozen for enums

* Add @frozen for structs, deprecate @_fixed_layout for them

* Switch usage from _fixed_layout to frozen
2019-05-30 17:55:37 -07:00
Karoy Lorentey
f0e04f73f4 [stdlib] Process elements from back to front 2018-12-18 09:49:58 -08:00
Karoy Lorentey
66db9b40b8 [stdlib] _HashTable.copyContents: Fix buffer overrun 2018-11-26 18:24:23 +00:00
Ben Cohen
1673c12d78 [stdlib] Replace "sanityCheck" with "internalInvariant" (#20616)
* Replace "sanityCheck" with "internalInvariant"
2018-11-15 20:50:22 -08:00
Karoy Lorentey
4967393618 Merge pull request #19688 from lorentey/hashed-bridgeobject
[stdlib] Set, Dictionary: Replace _Variant enums with _BridgeStorage
2018-10-08 12:07:40 +01:00
swift-ci
f9a2d90239 Merge pull request #19533 from lorentey/per-instance-seeding 2018-10-06 07:00:52 -07:00
Karoy Lorentey
bb2cb064ae [stdlib] Eliminate more overflow checks
This is a tiny code size improvement.
2018-10-05 12:33:25 +01:00
Karoy Lorentey
6cb546534e [stdlib] Dictionary: Force-inline native iterators 2018-10-03 13:23:47 +01:00
Karoy Lorentey
08e0ad66e3 [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,
2018-10-02 14:52:53 +01:00
Karoy Lorentey
b92c301e99 [stdlib] Set, Dictionary: Clean up storage allocation 2018-09-28 04:04:29 +01:00
Karoy Lorentey
91c5a310fa [stdlib] Set, Dictionary: Prepare for per-instance hash seeds
Implement the per-instance seeding infrastructure without actually enabling per-instance seeding.
2018-09-28 04:04:28 +01:00
Karoy Lorentey
d3178a0394 [stdlib] Tighten up Cocoa index validation for native sets/dictionaries
Like before, allow the use of Cocoa indices to access native sets/dictionaries, but approximate the same mutation count-based check as we do for native indices.

- Ensure that native collections that were converted from Cocoa have an age generated from the address of the original Cocoa object.
- To get the age of a Cocoa index, regenerate one from the object embedded in it.
- Compare self.age to index.age and trap if it doesn’t match.

# Conflicts:
#	stdlib/public/core/HashTable.swift
2018-09-27 19:11:19 +01:00
Karoy Lorentey
5705582ad9 [stdlib] _HashTable.Index: New struct
Set and Dictionary will start using this shortly as their native index types.
2018-09-27 01:49:51 +01:00
Karoy Lorentey
6358294be8 [stdlib] Set, Dictionary: Add a mutation count to storage ivars
The mutation count will allow us to recognize and trap on invalid indices more reliably. (However, it won’t be foolproof — some invalid indices may pass through the checks.)

- Change _scale to Int8 to make space for an extra Int32 without enlarging the storage header.
- Add an _age field inside the new gap.
- Initialize the age to a scrambled version of the storage address.
- Generate a new counter for every newly allocated storage instance, except for identical copy-on-write copies.
- Increment the mutation counter after every removal.
2018-09-27 01:49:50 +01:00
Karoy Lorentey
0fee12b56d [stdlib] Update _HashTable terminology
- Remove the old Index typealias for _HashTable.Bucket
- Rename _HashTable.AgedIndex to _HashTable.Index
- Rename _HashTable.Bucket.bucket to _HashTable.Bucket.offset
- Rename/update _HashTable members to adopt to new terminology
2018-09-27 00:12:35 +01:00
Karoy Lorentey
0cddeca3c4 [stdlib] _HashTable: Remove obsolete debug code 2018-09-27 00:12:20 +01:00
Karoy Lorentey
9b63c8b1b5 [stdlib] _HashTable: Prepare for upcoming renamings 2018-09-27 00:12:20 +01:00
Karoy Lorentey
b95ba2507d [stdlib] Add _HashTable implementing low-level hash table operations
_HashTable implements low-level hash table operations that are common between Set and Dictionary. It is a non-generic struct, dealing with maintaining hash table metadata rather than any actual elements.

_HashTable is intended as a mostly transparent abstraction. Most operations are inlinable, except for the ones related to the maximum load factor.
2018-09-22 02:04:05 +01:00