So sounds like locking it in 2 dimensions gives us the ability to do this one:
- non-atomic reference counts for classes that arenât Sendable and that weâre willing to guarantee are never shared between concurrent contexts
Do we have a protocol already that we can use to mark this way? Im guessing we don't want all classes not marked sendable to suddenly have this.
And yeah, I thought that's what you mean by "strict single -ownership" - just like to ask. And "static lets" are very easy to use, as a bonus. What about static immutable caches? Can they just be no-ARC, shared by all?
This matches our use case pretty closely - we have a static cache handing out "heaps" on checkout to a Task, which owns the heap for its duration, and then hands it back. Our case is wide concurrency of same type objects, which use the caches "heaps" for doing their temp work, while emitting "permanent" objects. So the heaps would get checked out from the static let, and the Task could own it for its duration, and hand it back. We are currently doing this with DispatchQ's, etc, and it works fine, but im this would be simpler, and using your Task work, perhaps more performant, given the more gracious use of the concurrency stuff under the hood. (And definitely nicer to the dispatchQ folks wanting less thread explosion)
The heaps are preallocated structs and things in unsafebuffers, that are used ephemerally like a stack, but there's some init work to be done, so we save a ton of cost keeping them at the ready.
This is an example of our usage:
if let heap = PhoneticComparisonHeap.heaps.take()
{
defer {
PhoneticComparisonHeap.heaps.put(heap)
}
took = true
let workID = heap.currentWorkID
heap.resetTemporaryPool()
let task = heap.localAllocRecogTask()
task.run()
}
We have these preallocated and one per worker thread. Typically 8-16 firing at once depending on CPU, but on big linux boxes with high CPU counts, 32,64, etc.)