-
Notifications
You must be signed in to change notification settings - Fork 24.8k
feat(iOS): get TurboModules conforming to protocol #53282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @tjzel thanks for the submission.
This code is critical and performance wise can be a problem. I don't think we can import this, to be fair.
It would be helpful to understand what do you want to achieve, to see if we can get there in a better and safer way.
auto * moduleName = pair.first.c_str(); | ||
Class moduleClass = [self _getModuleClassFromName:moduleName]; | ||
|
||
if ([moduleClass conformsToProtocol:protocol]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checking whether a module conforms to a protocol is a very expensive operation (see the official docs).
Here we are also iterating over all the modules that are loaded in the the app. If this happens at startup or at critical time, for apps that have many modules, this can cause a startup time regression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was afraid this would be a blocker.
This is change is a part I extracted from #50788 because I figured out it could be useful anyway. I personally need it for the BundleConsumer interface from the aforementioned PR - I wanted to make an API usable for everyone, therefore needed a way to detect all the TurboModules that implement a given interface. More on that is in the proposal we talked about https://docs.google.com/document/d/1jo93F1gPD3xrXU1UMb5ahuZpIh4JITHd_-FC6lIzB_k
I also had an implementation that instead of conformsToProtocol
uses respondsToSelector
but I figured it's more or less the same implementation wise and performance wise.
Initially I did it using (a bit obscure) RCTModulesConformingToInterface but there's no respective codegen functionality for Android and I wanted to make the implementations similar.
Summary:
This is an analogous PR to
but on iOS.
The implementation is very simple.
Changelog:
[IOS] [ADDED] - Allow to get TurboModules conforming to given protocol
Test Plan: