If you put me in charge of objc_msgSend, I think I’d have the compiler scatter a couple of polymorphic inline caches into the binary at each call site (using indirect jumps to satisfy W^X). I think it’d reduce insn count from 11 to ~6, and it would use the BTB better.
-
Show this thread
-
Specifically, a call to objc_msgSend would have this fast path: cbz self,cache_miss ; nil check ldp type/targetcache ; compiler generates a slot ldr self->isa cmp typecache,isa bne cache_miss br targetcache
2 replies 0 retweets 2 likesShow this thread -
In fact, now that I think about it, it’d be pretty doable to use PGO to devirtualize Objective-C method calls…
3 replies 0 retweets 6 likesShow this thread -
Replying to @pcwalton
You'd still need some way to notice when the method implementation is changed at runtime and fall back into msgSend.
1 reply 0 retweets 0 likes
Yeah, I was thinking if you’re doing weird runtime shenanigans you just nuke all the caches. Could also use a global epoch or something at the cost of an insn or two more
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.