Post #1171273
2025-10-30 00:18 UTC
If you, like me, have ever been annoyed at the wastefulness of allocating a whole Array or Set just to store one object to pass to something:
1: change the thing you're passing it to from [Foo] to some Collection<Foo> or some RandomAccessCollection<Foo>
2: replace your Array with a CollectionOfOne
No allocations, no refcounting, no indirection :)
#swiftlang
Replies (4)
-
@numist@xoxo.zone 2025-10-30 00:43
@catfish_man type erasure to improve performance? hang on I gotta check my calendar
-
@tkrajacic@graz.social 2025-10-30 05:41
@Catfish_Man there should really be a document listing such performance tricks and explaining them. Otherwise… care to write a book? 🙃
-
@pretz@mastodon.social 2025-10-30 05:57
@Catfish_Man I would love a more concise syntax for “some Collection” I would use it a lot more if it didn’t always look like I was being overly clever.
-
@vrutberg@masto.nu 2025-10-30 08:35
@Catfish_Man Wow, to be honest, this has never even crossed my mind. But now I feel like it should have. :-) In “everyday code”, how much of a practical efficiency win is this? I suppose in code that is more algorithmic in nature (needs to be as efficient and performant as possible), I imagine this could have a real impact, but otherwise?