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

Reduce web bundle size #5203

Merged
merged 15 commits into from
Oct 16, 2023

Conversation

bartlomiejbloniarz
Copy link
Contributor

Summary

This PR moves some web implementations to .web.ts files, so that native implementations are excluded from the bundle. Some changes here might be controversial (e.g. SharedTransition.web.ts), since they introduce some level of code duplication. These changes, however, allow webpack to better recognize which code should be excluded from the bundle.

While working on this issue I also found some other areas that can be changed in the future to further optimize the bundle size:

  • lazy load layout animations on web
  • change the plugin to exclude some worklet fields (e.g. code) on web (afaik there is no babel supported way to recognize if we are on web)

Test plan

Run yarn build in NextExample. The difference between reanimated.js and noreanimated.js should be around 43kB.

@bartlomiejbloniarz bartlomiejbloniarz marked this pull request as ready for review October 9, 2023 15:18
@tomekzaw
Copy link
Member

tomekzaw commented Oct 9, 2023

  • change the plugin to exclude some worklet fields (e.g. code) on web (afaik there is no babel supported way to recognize if we are on web)

Sounds like something worth doing. For now, we could support it via some environment variable, e.g. REANIMATED_BABEL_PLUGIN_BUNDLE_FOR_WEB=1 (or something shorter) which can be enabled on demand. cc @tjzel

Copy link
Member

@tomekzaw tomekzaw left a comment

Choose a reason for hiding this comment

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

Overall the approach is correct but there are still some little things to be addressed prior to merging. I've left a few suggestions, but let's write them down and apply them in separate PRs. Let's keep the scope of this PR as web-oriented as possible and we can improve other things later.

src/reanimated2/PlatformChecker.ts Outdated Show resolved Hide resolved
src/reanimated2/SetNativeProps.ts Show resolved Hide resolved
src/reanimated2/SetNativeProps.web.ts Outdated Show resolved Hide resolved
src/reanimated2/dispatchCommand.ts Outdated Show resolved Hide resolved
src/reanimated2/dispatchCommand.ts Outdated Show resolved Hide resolved
src/reanimated2/measure.ts Outdated Show resolved Hide resolved
src/reanimated2/NativeReanimated/index.web.ts Outdated Show resolved Hide resolved
src/reanimated2/NativeMethods.ts Show resolved Hide resolved
Base automatically changed from @bartlomiejbloniarz/reduce-web-bundle-size to main October 13, 2023 15:34
src/reanimated2/index.ts Outdated Show resolved Hide resolved
src/reanimated2/nativeMethods/dispatchCommand.web.ts Outdated Show resolved Hide resolved
Copy link
Member

@tomekzaw tomekzaw left a comment

Choose a reason for hiding this comment

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

Great job! 👏

@bartlomiejbloniarz bartlomiejbloniarz added this pull request to the merge queue Oct 16, 2023
Merged via the queue into main with commit fcd6b95 Oct 16, 2023
8 checks passed
@bartlomiejbloniarz bartlomiejbloniarz deleted the @bartlomiejbloniarz/reduce-bundle-size-web-2 branch October 16, 2023 10:29
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.

None yet

5 participants