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

feat: load hermes-parser conditionally when hermes is enabled #855

Closed

Conversation

EvanBacon
Copy link
Contributor

Summary

The package hermes-parser has a lot of JS that goes unused in web platforms, this leads to increased bundle time.

Test plan

Before

transform[stdout]: parse: 89.201ms
transform[stdout]: parse: 94.381ms
transform[stdout]: parse: 107.966ms
transform[stdout]: parse: 127.707ms
transform[stdout]: parse: 411.933ms
transform[stdout]: parse: 88.575ms
transform[stdout]: parse: 114.977ms
transform[stdout]: parse: 119.187ms

After

transform[stdout]: parse: 32.369ms
transform[stdout]: parse: 36.327ms
transform[stdout]: parse: 46.021ms
transform[stdout]: parse: 74.98ms
transform[stdout]: parse: 306.212ms
transform[stdout]: parse: 33.792ms
transform[stdout]: parse: 52.749ms
transform[stdout]: parse: 71.474ms

The package `hermes-parser` has a lot of JS that goes unused in web platforms, this leads to increased bundle time.
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Aug 19, 2022
@facebook-github-bot
Copy link
Contributor

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

Copy link
Contributor

@robhogan robhogan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@facebook-github-bot
Copy link
Contributor

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

facebook-github-bot pushed a commit that referenced this pull request Aug 25, 2022
Summary:
- There are [general performance improvements](#855) from conditionally importing Hermes.
- `metro-hermes-compiler` is doing some gnarly error handling that makes debugging Metro quite painful.

If you get an error in Metro after `metro-hermes-compiler` has been loaded, it will look something like:

<img width="1900" alt="Screen Shot 2022-08-23 at 1 28 43 PM" src="https://user-images.githubusercontent.com/9664363/186146899-57817ce9-9cef-439b-a421-98b9aec216fb.png">

This PR doesn't fix the core issue but it does alleviate Metro web and JSC development where Hermes is not used:

```
TypeError [ERR_INVALID_ARG_TYPE]: The "to" argument must be of type string. Received undefined
    at new NodeError (node:internal/errors:371:5)
    at validateString (node:internal/validators:119:11)
    at Object.relative (node:path:1192:5)
    at MetroTerminalReporter._getBundleStatusMessage (/Users/evanbacon/Documents/GitHub/expo/packages/expo/cli/build/src/start/server/metro/MetroTerminalReporter.js:44:41)
    at /Users/evanbacon/Documents/GitHub/expo/node_modules/metro/src/lib/TerminalReporter.js:393:14
    at Array.map (<anonymous>)
    at MetroTerminalReporter._getStatusMessage (/Users/evanbacon/Documents/GitHub/expo/node_modules/metro/src/lib/TerminalReporter.js:392:8)
    at MetroTerminalReporter.update (/Users/evanbacon/Documents/GitHub/expo/node_modules/metro/src/lib/TerminalReporter.js:423:31)
    at Object.update (/Users/evanbacon/Documents/GitHub/expo/packages/expo/cli/build/src/start/server/metro/instantiateMetro.js:21:30)
    at Server.requestProcessor [as _processBundleRequest] (/Users/evanbacon/Documents/GitHub/metro/packages/metro/src/Server.js:653:22)
    at async Server._processRequest (/Users/evanbacon/Documents/GitHub/metro/packages/metro/src/Server.js:504:9)
```

Pull Request resolved: #856

Test Plan: Throw an error somewhere in the resolver, Metro will throw a reasonable Node error instead of the Hermes error.

Reviewed By: motiz88

Differential Revision: D38940701

Pulled By: cipolleschi

fbshipit-source-id: 472fa775c5ae6a39acb6d0195f926a1013a4b425
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. 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.

None yet

3 participants