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

Archiving IOS build is taking a lot of time after enabling hermes and MetroSerializer #2424

Closed
2 of 5 tasks
amanmoar277 opened this issue May 19, 2023 · 4 comments
Closed
2 of 5 tasks
Labels
bug Something isn't working feature: cli This is related to CLI needs author feedback

Comments

@amanmoar277
Copy link

amanmoar277 commented May 19, 2023

What happened?

I am trying to archive the IOS build with hermes enabled, but it is taking a lot of time i.e. (~15-20x) times the time taken to build when hermes is disabled. I have tried this on multiple RN versions like 0.68.0, 0.71.8.

Even a simple RN app is taking almost 1 hour 15 minutes to archive the IOS build with hermes enabled and using esbuild bundler.

I am able to archive the build properly (i.e. without any effect on build time) in the following scenarios -

  1. After disabling hermes and using the @rnx-kit packages such as
    a. @rnx-kit/babel-preset-metro-react-native
    b. @rnx-kit/metro-config
    c. @rnx-kit/metro-serializer-esbuild
  2. After using the default babel and metro config (which is shipped by default with RN project)

The esbuild is able to generate the JS bundle successfully in every scenario but the following step is causing issue.

Showing Recent Issues

  • /Users/AwesomeProject/ios/Pods/hermes-engine/destroot/bin/hermesc -emit-binary -O -out /Users/Library/Developer/Xcode/DerivedData/AwesomeProject-gfqsdgqywjohyjfoxkrvubakbthd/Build/Intermediates.noindex/ArchiveIntermediates/AwesomeProject/BuildProductsPath/Release-iphoneos/AwesomeProject.app/main.jsbundle /Users/Library/Developer/Xcode/DerivedData/AwesomeProject-gfqsdgqywjohyjfoxkrvubakbthd/Build/Intermediates.noindex/ArchiveIntermediates/AwesomeProject/BuildProductsPath/Release-iphoneos/main.jsbundle
Screenshot 2023-05-19 at 4 43 43 PM





Here is the metro and babel config which I am using.


Screenshot 2023-05-19 at 4 32 00 PM


Screenshot 2023-05-19 at 4 32 10 PM

package.json


Screenshot 2023-05-19 at 4 33 50 PM

I can't figure out why this is happening. Please let me know if I am missing some config here.

Affected Package

@rnx-kit/metro-serializer-esbuild, @rnx-kit/metro-config, @rnx-kit/babel-preset-metro-react-native

Version

0.1.23, 1.3.6, 1.1.4

Which platforms are you seeing this issue on?

  • Android
  • iOS
  • macOS
  • Windows

System Information

% npx react-native info
info Fetching system and libraries information...
System:
    OS: macOS 13.3.1
    CPU: (8) x64 Apple M1
    Memory: 73.29 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 14.21.3 - ~/.nvm/versions/node/v14.21.3/bin/node
    Yarn: Not Found
    npm: 6.14.18 - ~/.nvm/versions/node/v14.21.3/bin/npm
    Watchman: 2023.04.10.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.12.0 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
    Android SDK: Not Found
  IDEs:
    Android Studio: 2022.1 AI-221.6008.13.2211.9619390
    Xcode: 14.3/14E222b - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.18 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.8 => 0.71.8 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to Reproduce

  1. Install the above mentioned libs.
  2. Change the babel.config.js and metro.config.js, as described in above mentioned screenshot.
  3. Try to archive the IOS build.
  4. The build process will take a lot of time in the following step (after successfully generating the JS bundle)
  • /Users/AwesomeProject/ios/Pods/hermes-engine/destroot/bin/hermesc -emit-binary -O -out /Users/Library/Developer/Xcode/DerivedData/AwesomeProject-gfqsdgqywjohyjfoxkrvubakbthd/Build/Intermediates.noindex/ArchiveIntermediates/AwesomeProject/BuildProductsPath/Release-iphoneos/AwesomeProject.app/main.jsbundle /Users/Library/Developer/Xcode/DerivedData/AwesomeProject-gfqsdgqywjohyjfoxkrvubakbthd/Build/Intermediates.noindex/ArchiveIntermediates/AwesomeProject/BuildProductsPath/Release-iphoneos/main.jsbundle

Code of Conduct

  • I agree to follow this project's Code of Conduct
@amanmoar277 amanmoar277 added the bug Something isn't working label May 19, 2023
@tido64
Copy link
Member

tido64 commented May 19, 2023

Hi @amanmoar277, I wonder if this is also related to #2416 and #2419. Can you try adding -w to the hermesc command and see if that helps? I suspect it has something to do with the warnings that are output by the compiler.

@Thanaen
Copy link

Thanaen commented May 23, 2023

Hello,
I confirm that passing the "-w" argument to the hermes call solves the problem.

However, I didn't find a clean way to do this. 😕
I had to manually modify the node_modules/react-native/scripts/react-native-xcode.sh file to be able to modify the arguments passed to Hermes.

@tido64
Copy link
Member

tido64 commented May 23, 2023

What you also can try to do is setting minifyWhitespace: false. This tells esbuild to not remove whitespaces, which will create shorter lines for Hermes to output:

const { makeMetroConfig } = require("@rnx-kit/metro-config");
const { MetroSerializer, esbuildTransformerConfig } = require("@rnx-kit/metro-serializer-esbuild");

module.exports = makeMetroConfig({
  serializer: {
    customSerializer: MetroSerializer([], {
      minify: true,
      minifyWhitespace: false,
      minifyIdentifiers: true,
      minifySyntax: true,
    }),
  },
  transformer: esbuildTransformerConfig,
});

Documentation: https://github.com/microsoft/rnx-kit/tree/main/packages/metro-serializer-esbuild#minifywhitespace

@tido64
Copy link
Member

tido64 commented May 23, 2023

For fix and workaround, see #2416 (comment).

@tido64 tido64 closed this as completed May 23, 2023
facebook-github-bot pushed a commit to facebook/react-native that referenced this issue May 23, 2023
Summary:
Limit diagnostics width output by `hermesc` as they may cause slowdowns or even crashes in Gradle/Xcode when a minified bundle is used as input. This occurs because Hermes is unable to determine the terminal width when executed by Gradle/Xcode, and falls back to "unlimited". If the input is a minified bundle, Hermes will output the whole bundle for each warning.

See issues filed:
- microsoft/rnx-kit#2416
- microsoft/rnx-kit#2419
- microsoft/rnx-kit#2424

## Changelog:

[GENERAL] [FIXED] - Limit diagnostics width output by `hermesc`

Pull Request resolved: #37531

Test Plan: See listed issues for repros.

Reviewed By: cipolleschi

Differential Revision: D46102686

Pulled By: cortinico

fbshipit-source-id: 1b821cad7ef0d561a5e1c13a7aedf9b10164620a
kelset pushed a commit to facebook/react-native that referenced this issue May 25, 2023
Summary:
Limit diagnostics width output by `hermesc` as they may cause slowdowns or even crashes in Gradle/Xcode when a minified bundle is used as input. This occurs because Hermes is unable to determine the terminal width when executed by Gradle/Xcode, and falls back to "unlimited". If the input is a minified bundle, Hermes will output the whole bundle for each warning.

See issues filed:
- microsoft/rnx-kit#2416
- microsoft/rnx-kit#2419
- microsoft/rnx-kit#2424

## Changelog:

[GENERAL] [FIXED] - Limit diagnostics width output by `hermesc`

Pull Request resolved: #37531

Test Plan: See listed issues for repros.

Reviewed By: cipolleschi

Differential Revision: D46102686

Pulled By: cortinico

fbshipit-source-id: 1b821cad7ef0d561a5e1c13a7aedf9b10164620a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature: cli This is related to CLI needs author feedback
Projects
None yet
Development

No branches or pull requests

3 participants