Objective-C Runtime +resolveInstanceMethod: Concurrency Guarantees Unclear
0 reputation · 13 May 2023, 01:46 UTC
Objective-C Runtime +resolveInstanceMethod: Concurrency Guarantees Unclear
The goal is to understand whether the Objective‑C runtime serializes concurrent invocations of +resolveInstanceMethod: when multiple threads send the same unknown selector, and how this affects latency.
Current documentation does not specify if the runtime guarantees a single call per selector or allows parallel execution. This uncertainty creates a potential performance bottleneck in multithreaded environments, as lock contention may occur while the method list is modified.
Key constraints:
- Concurrent threads may simultaneously trigger
+resolveInstanceMethod:for the same selector. - The runtime may employ internal locking that is not documented.
- Latency is only observable under heavy concurrent loads.
Unresolved questions:
- Is
+resolveInstanceMethod:guaranteed to be invoked only once per selector when multiple threads send the same missing selector concurrently? - Does the runtime serialize concurrent invocations of
+resolveInstanceMethod:to protect the method list, or can they proceed in parallel? - What best‑practice patterns can developers adopt to mitigate potential lock‑contention latency in performance‑critical paths?