3 ms·
>8/ Another "magic" trick is how their "Swift" programming language uses "reference counting" instead of the "garbage collection" in Android. They did something
by muststopmyths 6y ago
>8/ Another "magic" trick is how their "Swift" programming language uses "reference counting" instead of the "garbage collection" in Android. They did something in their CPU to double the speed of reference counting.
What the hell does that even mean ?
Disregarding the nonsensical attribution of magic to Swift vs Java, if "reference counting" on translated x86 code is faster, then I suppose M1 does "lock add / cmpxchng" or whatever faster than X86.
I would love to know how. Other than just as a side-effect of a SoC, UMA architecture.
- dathinab 6y ago> What the hell does that even mean ? > double the speed of reference counting The simplest low latency system memory making atomics faster in some contexts (faster cache write back/fetch). Then atomic operations (using Aquire/Release) are theoretically faster on ARM due to the weak memory ordering (I'm not sure if this does help for translated x86 code). Potentially other reasons can include: - maybe optimized fetch add/sub instructions (or more precise the ARM instructions used by fetch add/sub functions in higher level languages) - maybe tweaks to the coherence protocol - maybe specialized optimizations in the pipelineing All in all it means Apple focused on making sure fetch add/sub are fast (most likely as this is what is normally used for Rc).
- annilt 6y agoI think it says refcounting twice faster for swift on M1 compared to swift on x86. It is possible because if you don’t have TSO(total store order), you can employ atomic operations without waiting/flushing previous items in the CPU’s store buffer
- gpderetta 6y agoBut apparently they are faster even in TSO mode. Maybe they aggressively speculate around them.
- ksherlock 6y agoMaybe this: https://twitter.com/Catfish_Man/status/1326238434235568128 https://twitter.com/Catfish_Man/status/1326238434235568128 fun fact: retaining and releasing an NSObject takes ~30 nanoseconds on current gen Intel, and ~6.5 nanoseconds on an M1 ... Weaker memory model makes acquire-release atomics possible to implement much more efficiently, in exchange for not hiding some classes of multithreading bugs
- muststopmyths 6y agoI guess I understand the ARM behavior, but both this thread and the original one talk about x86 retain/release being faster on M1 as well. That's the part I'd love someone knowledgeable to explain.