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

Don't compile Hermes-supported features with Babel #1773

Merged
merged 2 commits into from
Oct 31, 2023
Merged

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Oct 31, 2023

This simplifies the generated code to be closer to the code we actually write.

Concretely:

  • Hermes already supports a bunch of features that we're currently compiling with Babel. Pass an option to target the subset needed by Hermes specifically, and let Hermes handle the rest.
  • Although Hermes supports object spread, the Expo preset adds it back. Explicitly patch the Expo preset to disable it.

We will be able to remove both of these overrides when we upgrade Expo:

However, I don't know when we'll get to updating, so why not fix this now.

Test plan

Walked around the app. App seems to work. Equivalent changes being in newer Expo releases give some confidence.

Bundle output changes

Glance over the bundle diff.

Function names are now implied (since Hermes can do this):

Screenshot 2023-10-30 at 23 49 46

Native support for ?? and ?. and friends:

Screenshot 2023-10-30 at 23 50 00

No runtime code needed for rest/spread:

Screenshot 2023-10-30 at 23 49 51

Also, we finally get rid of this _objectSpread helper:

Screenshot 2023-10-30 at 23 52 35

Fun fact: this _objectSpread helper was duplicated in our bundle almost three thousand times 500 times (with 3000 call sites).

Total minified PROD bundle went down from 8.9 MB to 8.6 MB.

Spreads in particular are very common so having them go through fewer indirections is nice.

We're using Hermes, and Hermes supports object spread.
We can remove this patch when we upgrade Expo because it'll be conditional there.
@gaearon gaearon requested a review from pfrazee October 31, 2023 00:18
Copy link
Collaborator

@pfrazee pfrazee left a comment

Choose a reason for hiding this comment

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

Ahhh very nice

@gaearon gaearon merged commit 515c9d5 into main Oct 31, 2023
@gaearon gaearon deleted the babel-tweaks branch October 31, 2023 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants