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

perf: only use project params, this can let native.gradle file Load … #2193

Conversation

feiyang1235
Copy link

@feiyang1235 feiyang1235 commented Dec 5, 2023

…only once in setting.gradle

Summary:

before:
we use cli-platform-android
in settings.gradle

apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)

in app/build.gradle

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

We can see that this will load the native_modules.gradle file twice, this will cause two traversals of the node_ Modules folder.

Now:
We can change the applyNativeModulesAppBuildGradle method to be a pure function, so that we can only load native_module.gradle in settings. gradle file

in settings.gradle

apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle");
applyNativeModulesSettingsGradle(settings)
gradle.ext.applyNativeModulesAppBuildGradle = applyNativeModulesAppBuildGradle

in app/build.gradle

gradle.ext.applyNativeModulesAppBuildGradle(project)

Test Plan:

Use the configuration above, can successfully complete autolink
Checklist

  • [ OK] Documentation is up to date to reflect these changes.
  • [ OK] Follows commit message convention described in CONTRIBUTING.md

@cortinico
Copy link
Member

In theory this is a good change. The problem is that it will create trash inside the template. Instead we should move those functions inside react-native so there is no need to migrate the template at all (users can just remove those lines)

@feiyang1235
Copy link
Author

feiyang1235 commented Dec 6, 2023

In theory this is a good change. The problem is that it will create trash inside the template. Instead we should move those functions inside react-native so there is no need to migrate the template at all (users can just remove those lines)

In fact, if no this change. Users cannot remove those lines.
There are two reasons

  1. This(My Pull Request)change is compatible with the previous template
  2. Users can modify the configuration to obtain performance optimization if they need (Actually I faced this problem in my project, Use the pull request code and modify the configuration, my project compiles 20% faster).

@cortinico
Copy link
Member

In fact, if no this change. Users cannot remove those lines.

Can you clarify what you mean with this sentence?

Users can modify the configuration to obtain performance optimization if they need (Actually I faced this problem in my project, Use the pull request code and modify the configuration, my project compiles 20% faster).

Also can you clarify how those lines are introducing a 20% build performance regression for you?

@feiyang1235
Copy link
Author

feiyang1235 commented Dec 6, 2023

In fact, if no this change. Users cannot remove those lines.

Can you clarify what you mean with this sentence?

example:
in settings.gradle

apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); 
applyNativeModulesSettingsGradle(settings)

in app/build.gradle

// I want to delete this line,  cuz I think  apply native_modules.gradle is a time-consuming operation(the reason is in the below reply). I want to use the exported extension named applyNativeModulesAppBuildGradle in  settings.gradle,But their contexts are inconsistent.
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); 
applyNativeModulesAppBuildGradle(project)

Users can modify the configuration to obtain performance optimization if they need (Actually I faced this problem in my project, Use the pull request code and modify the configuration, my project compiles 20% faster).

Also can you clarify how those lines are introducing a 20% build performance regression for you?

What I mean is that both build. gradle and settings. gradle executed apply from: file once ("../node-modules/@ react native community/cli platform android/native_modules. gradle"); This leads to native_modules.gradle script file is executed twice, When the native_modules.gradle script is executed, the ReactNativeModules object will be instantiated, and the instantiation process will execute the getReactNativeConfig() method, which will traverse the node_ modules directory, which may be a time-consuming method when there are many dependencies

Copy link

github-actions bot commented Mar 6, 2024

There hasn't been any activity on this pull request in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

@github-actions github-actions bot added the stale label Mar 6, 2024
@github-actions github-actions bot closed this Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants