Monday, June 7, 2021

Kernel Assisting the Objective-C Runtime

This is really cool, and I just realized that I forgot to link to it after last year’s WWDC.

Pierre Habouzit:

Faster, priority-inversion-less GC (speed)

@mikeash wrote about it a long time ago, however it turns out this was relatively slow and could also fail (if a thread was observed in the critical section).

The general idea is still the same, but instead of observing the other threads PC, we use a scheme where at startup the runtime tells the kernel where the code reading the IMP caches “unsafely” is, and gives a “recovery PC”.

Now when a GC is triggered, instead of asking for all the other threads PCs, the kernel is told to “force” the PC of threads in the critical section to the recovery path, there’s no waiting, and it can’t fail.

it’s also 10-100x as fast as before.

David Smith:

This is one of the wildest optimizations I’ve seen. How do you make a reader-writer lock with zero instructions? You uh… ask the kernel to move all the reader threads out of the critical section 😱😱😱

Just like… longjmp someone else from outside 🤯

Pierre Habouzit:

I really feel that working at @Apple gives one a unique convergence of “all the things” that is mostly unmatched in the rest of the industry and some of us are lucky enough to have the opportunity to take advantage of it ;)

Previously:

Comments RSS · Twitter

Leave a Comment