You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One benefit of the naivemethod_exchangeImp approach is that we can use standard objc_msgSend when calling the original method, which means we benefit from the method cache. However, with ZKSwizzle the ZKOriginalImplementation calls class_getInstanceMethod which bypasses the cache. Moreover, the need to call classFromInfo (which I believe was added so we can statically resolve the caller to namespace to avoid issues if we do multiple swizzlings) is probably some additional overhead in a hotloop.
which I'm not sure why we convert to strings to check instead of comparing the class pointers directly.
While I doubt these matter much for most cases, in the case where you are swizzling a method that is in a hotloop, these might impact performance.
I guess you could at least eliminate the overhead from classFromInfo by offering a version of the macro where you manually pass in the siwzzled class name (sadly C doesn't have a macro like _CLASS_, nor does it have consteval support). However with this method of swizzling, I don't think it's possible to make use of the method cache because just calling objc_msgsend will end up sending the wrong _cmd like you noted in the readme. One possible way around this is to cache things ourselves, but that's probably introducing more overhead and complexity. Another option would be to have a bunch of globals (or a hash map) for the old imp which we set when calling method_exchangeImplementations, so we can then directly call the imp without even needing to look it up.
The text was updated successfully, but these errors were encountered:
One benefit of the naive
method_exchangeImp
approach is that we can use standardobjc_msgSend
when calling the original method, which means we benefit from the method cache. However, with ZKSwizzle theZKOriginalImplementation
callsclass_getInstanceMethod
which bypasses the cache. Moreover, the need to callclassFromInfo
(which I believe was added so we can statically resolve the caller to namespace to avoid issues if we do multiple swizzlings) is probably some additional overhead in a hotloop.There's also the
which I'm not sure why we convert to strings to check instead of comparing the class pointers directly.
While I doubt these matter much for most cases, in the case where you are swizzling a method that is in a hotloop, these might impact performance.
I guess you could at least eliminate the overhead from
classFromInfo
by offering a version of the macro where you manually pass in the siwzzled class name (sadly C doesn't have a macro like_CLASS_
, nor does it have consteval support). However with this method of swizzling, I don't think it's possible to make use of the method cache because just callingobjc_msgsend
will end up sending the wrong_cmd
like you noted in the readme. One possible way around this is to cache things ourselves, but that's probably introducing more overhead and complexity. Another option would be to have a bunch of globals (or a hash map) for the old imp which we set when callingmethod_exchangeImplementations
, so we can then directly call the imp without even needing to look it up.The text was updated successfully, but these errors were encountered: