News for hackers. Stuff that matters.
Re:Apple Silicon M1: Black Magic Fuckery by ubercow13 on Tuesday November 24, 2020 @06:40PM (#25204327)
How does this work? Isn't reference counting a lot of +1 and -1?
Re:Apple Silicon M1: Black Magic Fuckery by estebank on Tuesday November 24, 2020 @07:03PM (#25204486)
It is a lot of atomic +1 and -1, meaning possible thread contention, meaning that no matter how many cores your hardware has you have a worst case scenario where all your atomic reference counted objects have to be serialized, slowing everything down. I do not know how ObjectiveC/Swift deals with this normally, but making that operation as fast as possible on the hardware can have huge implications in real life, as evidenced by the new Macs.
Re:Apple Silicon M1: Black Magic Fuckery by gpderetta on Tuesday November 24, 2020 @06:59PM (#25204455)
On intel atomically increnting a counter is always sequentially consistent. ARM might get away with weaker barriers.
Re:Apple Silicon M1: Black Magic Fuckery by dathinab on Tuesday November 24, 2020 @07:15PM (#25204573)
It's a lot +-1 on atomic variables guarded using atomic memory operations (mainly with the Aquire/Release ordering) on memory which might be shared between threads.

So low latency of the cache to system RAM can help here, at least for cases where the Rc is shared between threads. But also if the thread is not shared between threads but the thread is moved to a different CPU. Still it's probably not the main reason.

Given how atomic (might) be implemented on ARM and that the cach and memory is on the same chip my main guess is that they did some optimizations in the coherency protocol/implementation (which keeps the memory between caches and the system memory/RAM coherent). I believe there is a bit of potential to optimize for RC, i.e. to make that usage pattern of atomics fast. Lastly they probably take special care that the atomic related instructions used by Rc are implemented as efficient as possible (mostly fetch_add/fetch_sub).

Re:Apple Silicon M1: Black Magic Fuckery by dirtypersian on Wednesday November 25, 2020 @01:35AM (#25206508)
Just to be clear, the RAM/memory and cache are not on the same chip/die/silicon. They are part of the same packaging though.

> which keeps the memory between caches and the system memory/RAM coherent Isn't this already true of every multi-core chip ever designed; the whole point of coherency is to keep the RAM/memory coherent between all the cores and their caches.

Re:Apple Silicon M1: Black Magic Fuckery by dathinab on Wednesday November 25, 2020 @04:49PM (#25214671)
Oh, right.

> Isn't this already true of every multi-core chip ever designed;

Yes, I just added the explanation of what coherency is in this context as I'm not sure how common the knowledge about it is.

The thing is there are many ways how you can implement this (and related things) with a number of parameters involved which probably can be tuned to optimize for typical RC's usage of atomic operations. (Edit: Just to be clear there are constraints on the implementation imposed by it being ARM compatible.)

A related example (Not directly atomic fetch add/sub and not directly coherency either) would be the way LL/SC operations are implemented. Mainly on ARM you have a parameter of how large the memory region "marked for exclusive access" (by an LL-load operation) is. This can have mayor performance implications as it directly affects how likely a conditional store fails because of accidental inference.