Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tjzel
Copy link
Contributor

@tjzel tjzel commented Aug 14, 2025

Summary:

This is an analogous PR to

The implementation is very simple.

Changelog:

[IOS] [ADDED] - Allow to get TurboModules conforming to given protocol

Test Plan:

Screenshot 2025-08-14 at 21 25 00

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 14, 2025
@tjzel tjzel marked this pull request as ready for review August 14, 2025 19:26
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 14, 2025
Copy link
Contributor

@cipolleschi cipolleschi left a 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]) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Software Mansion Partner: Software Mansion Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants