Skip to content

[Docs] Tree-shaking benchmark of RN app #581

Open

Description

@jbroma

Summary

Add page to docs that will showcase potential gains obtained through the use of tree-shaking.

We could also add few tips how to optimize the codebase to squeeze even more out of tree-shaking, also backed with data.

Activity

  1. added
    type:documentationImprovements or additions to Re.Pack documentation
    help wantedespecially welcoming for external contributions
    on Apr 24, 2024
  2. thymikee commented on Apr 24, 2024

    @thymikee
    Member
  3. github-actions commented on May 25, 2024

    @github-actions
    Contributor

    This issue has been marked as stale because it has been inactive for 30 days. Please update this issue or it will be automatically closed in 14 days.

  4. github-actions commented on Jun 26, 2024

    @github-actions
    Contributor

    This issue has been marked as stale because it has been inactive for 30 days. Please update this issue or it will be automatically closed in 14 days.

  5. matthargett commented on Jun 26, 2024

    @matthargett

    I'd still really like to see this, especially to track new rspack versus old webpack backend as time goes on.

  6. github-actions commented on Aug 25, 2024

    @github-actions
    Contributor

    This issue has been marked as stale because it has been inactive for 30 days. Please update this issue or it will be automatically closed in 14 days.

  7. matthargett commented on Sep 5, 2024

    @matthargett

    another optimization scenario that affects React hot path: https://gitlab.com/seaofvoices/darklua/-/issues/44

  8. 3 remaining items

  9. reopened this on Nov 1, 2024
  10. added
    pinnedKeeps this issue or PR active and prevents it from going stale.
    on Nov 1, 2024
  11. fardad-dev commented on Dec 14, 2024

    @fardad-dev
    Contributor

    Tree shaking doesn't work in module federation, is there any solution?

  12. jbroma commented on Jan 28, 2025

    @jbroma
    ContributorAuthor

    Tree shaking doesn't work in module federation, is there any solution?

    if you declare module as shared then treeshaking of that module is disabled - its not possible to determine what to treeshake then since a remote might be using parts of a shared dependency that the host is not using

  13. fardad-dev commented on Jan 29, 2025

    @fardad-dev
    Contributor

    You are right, but modules are not shared doesn't tree shaking too, i found the reason of it.
    we are using babel plugin of react-native which transforming es module import to commonjs require
    this will help

                         [
                            "module:@react-native/babel-preset",
                            {
                                disableImportExportTransform: true,
                            },
                        ],
    
  14. fardad-dev commented on Jan 29, 2025

    @fardad-dev
    Contributor

    tree shaking just working with import/export to enable it we should not transform them

  15. jbroma commented on Jan 29, 2025

    @jbroma
    ContributorAuthor

    tree shaking just working with import/export to enable it we should not transform them

    you're absolutely correct here - RN babel contains a plugin that converts every module transformed to CJS and CJS modules are very hard to treeshake 👍

  16. matthargett commented on Jan 29, 2025

    @matthargett

    Dead code elimination is not just about eliminating modules that aren't imported/required. In the darklua examples above, major hot paths in the Rect reconciler can be optimized with a combination of inlining, const propagation, and compile-time eval. Most of the branches checking values in *FeatureeFlags.js files can be eliminated.

    Webpack has plugins for const propagation and compile-time boolean evaluation, and if Rspack doesn't also have this capability, then I'd expect Rspack/Repack to perform significantly worse versus a well-tuned Webpack config.

  17. jbroma commented on Jan 30, 2025

    @jbroma
    ContributorAuthor

    @matthargett @HosseinMD did some direct comparison between Metro and Re.Pack here, your feedback would be greatly appreciated:

    https://github.com/jbroma/rn-treeshake-benchmark

    there is no in depth analysis or a case study based on that but it's a start :)

  18. matthargett commented on Feb 3, 2025

    @matthargett

    Thank you! Looks like there is work to do since RePack is currently 3MB larger on the production bundle than Metro. I was more interested in the difference with the Webpack-based RePack before transitioning to Rspack, as we know Haul roundly beat Metro in terms of bundle size in 2019.

    So, now I'm curious what the roadmap is to claw back that 3MB that Rspack has regressed. Will the final non-RC release be held until this gap is closed? Or will the 5.x approach with Rspack be reverted? Or was the plan to support the 4.x line until 5.x doesn't have regressions for end-users of Repack applications?

  19. jbroma commented on Feb 3, 2025

    @jbroma
    ContributorAuthor

    Thank you! Looks like there is work to do since RePack is currently 3MB larger on the production bundle than Metro. I was more interested in the difference with the Webpack-based RePack before transitioning to Rspack, as we know Haul roundly beat Metro in terms of bundle size in 2019.

    It's not a regression, its expected with Rspack:

    Image

    Reference: https://rspack.dev/guide/optimization/tree-shaking#tree-shaking

  20. added this to the Re.Pack 5 milestone on Feb 4, 2025
  21. matthargett commented on Feb 7, 2025

    @matthargett

    I meant it's a regression versus Repack backed by webpack, which has a great reputation for optimizing bundle size better than Metro ever has. I might suggest working upstream in Rspack to try and get parity with the webpack-backed Repack before releasing this major version. If the intention is to maintain the webpack-based branch for a while, until the Rspack-based new version is competitive, I guess that's okay.

    It just seems like a complication of how to message it to users and the broader community, again given that Haul/Repack's consistent differentiator for 7 years was around bundle optimizations that makes users happy due to faster app launch times and OTA downloads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedespecially welcoming for external contributionspinnedKeeps this issue or PR active and prevents it from going stale.type:documentationImprovements or additions to Re.Pack documentation

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions