Skip to content
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

Make setJSEngineResolutionAlgorithm a public method #36715

Closed
wants to merge 2 commits into from

Conversation

SparshaSaha
Copy link
Contributor

@SparshaSaha SparshaSaha commented Mar 30, 2023

Summary:

setJSEngineResolutionAlgorithm is marked as private while it looks like it was intended to be public.
While the current implementation does not cause any issues as such, but in brownfield we will have the option to explicitly set the JS engine to hermes or jsc when initialising the ReactInstanceBuilder.

Right now, we look if the engine is set and if unset we look for the jsc engine. If jsc is not present we select hermes and this process unnecessary throws a warning.

Changelog:

[ANDROID][FIXED] - Changed the scope of setJSEngineResolutionAlgorithm to public from private. Brownfield apps should be able to setup the JSResolutionAlgorithm before hand.

Test Plan:

@facebook-github-bot facebook-github-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 Mar 30, 2023
@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,547,531 +0
android hermes armeabi-v7a 7,861,911 +0
android hermes x86 9,029,447 +0
android hermes x86_64 8,884,496 +0
android jsc arm64-v8a 9,167,632 +0
android jsc armeabi-v7a 8,358,032 +0
android jsc x86 9,224,304 +0
android jsc x86_64 9,482,162 +0

Base commit: a44d8a0
Branch: main

@facebook-github-bot
Copy link
Contributor

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@kelset kelset added p: Microsoft Partner: Microsoft Partner labels Mar 30, 2023
@cipolleschi
Copy link
Contributor

Hi @SparshaSaha, thank for the PR. However, I don't think we should change the visibility of this method.

The way a JS engine is set is through the setJavaScriptExecutorFactory, not through the setJSEngineResolutionAlgorithm.

If you look at the code down there, we create a ReactInstance using the defaultExecutorFactory or the one passed by the user. If there is a custom executor factory, the resolutionAlgorithm is not even considered.
For the defaultFactory, we check what is set and we try to create the appropriate algorithm.

Making this public can create inconsistencies: what happens if the app passes a JSCExecutorFactory, but it set an HermesResolutionAlgorithm? By keeping the algorithm private, we can ensure consistency.

Does this make sense?

Also, there is another problem: when we build for Hermes, we don't have the JSC symbols in the build, so we cannot really allow to set different resolution algorithms.

@SparshaSaha
Copy link
Contributor Author

SparshaSaha commented Mar 30, 2023

I see @cipolleschi . Thank you for taking a look at it. It makes sense.

However, in that case, do you think we can remove this method: setJSEngineResolutionAlgorithm altogether?
I can see it's private but not used within this class.

As far as I understand, this condition will always be true right?

If that's the case can we remove this altogether? The logger says, "You're not setting the JS Engine Resolution Algorithm. " + "We'll try to load JSC first, and if it fails we'll fallback to Hermes");
but there seems to be no existing way to set this variable.

@cipolleschi
Copy link
Contributor

yeah, you are right. I reached out to @cortinico who has more context on how this should be used. IIRC, we had to keep that variable for backward compatibility with the internal infra, unfortunately. But let's wait for his input! ;)

@cortinico
Copy link
Contributor

yeah, you are right. I reached out to @cortinico who has more context on how this should be used. IIRC, we had to keep that variable for backward compatibility with the internal infra, unfortunately. But let's wait for his input! ;)

Thanks for spotting this. You're right @SparshaSaha, we need to add a bit of logic as we're not properly populating the InstanceManager (that's why the method was unused). @javache took over this and is pushing a fix together with your change 👍

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Mar 30, 2023
@facebook-github-bot
Copy link
Contributor

@javache merged this pull request in cb376dd.

jeongshin pushed a commit to jeongshin/react-native that referenced this pull request May 7, 2023
Summary:
`setJSEngineResolutionAlgorithm` is marked as private while it looks like it was intended to be public.
While the current implementation does not cause any issues as such, but in brownfield we will have the option to explicitly set the JS engine to hermes or jsc when initialising the ReactInstanceBuilder.

Right now, we look if the engine is set and if unset we look for the jsc engine. If jsc is not present we select hermes and this process unnecessary throws a warning.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[ANDROID][FIXED] - Changed the scope of `setJSEngineResolutionAlgorithm` to public from private. Brownfield apps should be able to setup the JSResolutionAlgorithm before hand.

Pull Request resolved: facebook#36715

Reviewed By: cortinico

Differential Revision: D44535444

Pulled By: javache

fbshipit-source-id: ae91e50de10c993c80ed4bba6f2fece64af178c4
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
`setJSEngineResolutionAlgorithm` is marked as private while it looks like it was intended to be public.
While the current implementation does not cause any issues as such, but in brownfield we will have the option to explicitly set the JS engine to hermes or jsc when initialising the ReactInstanceBuilder.

Right now, we look if the engine is set and if unset we look for the jsc engine. If jsc is not present we select hermes and this process unnecessary throws a warning.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[ANDROID][FIXED] - Changed the scope of `setJSEngineResolutionAlgorithm` to public from private. Brownfield apps should be able to setup the JSResolutionAlgorithm before hand.

Pull Request resolved: facebook#36715

Reviewed By: cortinico

Differential Revision: D44535444

Pulled By: javache

fbshipit-source-id: ae91e50de10c993c80ed4bba6f2fece64af178c4
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. Merged This PR has been merged. p: Microsoft Partner: Microsoft Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants