Skip to content

Enable persistent cache in Faster + Rspack #10823

Closed

Description

@tats-u

Have you read the Contributing Guidelines on issues?

Motivation

Rspack 1.2.0-alpha.0 used in Faster 3.7 now supports the experimental persistent cache.

https://github.com/web-infra-dev/rspack/releases/tag/v1.2.0-alpha.0
https://rspack.dev/config/experiments#persistent-cache

We need to modify the following parts:

https://github.com/facebook/docusaurus/blob/97690abc9422307f9ca52267391d4f8d62752e79/packages/docusaurus/src/webpack/base.ts#L111

     if (props.currentBundler.name === 'rspack') {
       // TODO Rspack only supports memory cache (as of Sept 2024)
       // TODO re-enable file persistent cache one Rspack supports it
       //  See also https://rspack.dev/config/cache#cache
-      return undefined;
+      return true;
     }

https://github.com/facebook/docusaurus/blob/97690abc9422307f9ca52267391d4f8d62752e79/packages/docusaurus/src/webpack/base.ts#L144-L154

         // @ts-expect-error: Rspack-only, not available in Webpack typedefs
         incremental: !isProd && !process.env.DISABLE_RSPACK_INCREMENTAL,
+        cache: {
+          type: 'persistent',
+          // Some extra options
+       },
      };

Self-service

  • I'd be willing to do some initial work on this proposal myself.

Activity

  1. added
    proposal
    status: needs triage
    on Jan 7, 2025
  2. slorber commented on Jan 7, 2025

    @slorber
    Collaborator

    I tried already but it didn't work yet. It did rebuild faster but then the SSG failed. At best, we could expose this through env variables but I suspect it will fail on all sites. I'll ping the Rspack team about this when I have time to investigate a bit more (not this week, taking a break)

  3. removed
    status: needs triage
    on Jan 7, 2025
  4. tats-u commented on Jan 7, 2025

    @tats-u
    ContributorAuthor

    You have already tried it, and it's bad news that it fails in SSG (I only tried it in preview with single locale by directly overwriting the JS file in node_modules).
    The current API lacks name: `${name}-${mode}-${props.i18n.currentLocale}` (existing in Webpack), but is it fine?

  5. slorber commented on Jan 7, 2025

    @slorber
    Collaborator

    It's an initial version, afaik they plan to support the same options as Webpack.

    This cache name feature is indeed useful to create one cache per env (client/server) and locale (for i18n sites)

    See also my explanation here: web-infra-dev/rspack#5658 (comment)


    BTW beta.0 is out right now: https://github.com/web-infra-dev/rspack/releases/tag/v1.2.0-beta.0

  6. tats-u commented on Jan 7, 2025

    @tats-u
    ContributorAuthor

    The design of the API has not been confirmed. I see.

    The type of buildDependencies is different too. Webpack is object but Rspack is array. Looks like it's not critical now because we have only to extract .config.

    I noticed the release of beta from the subscribed direct notification from Rspack.
    I don't think its persistent cache is compatible with the current Docusaurus.

  7. jerrykingxyz commented on Jan 9, 2025

    @jerrykingxyz

    The type of buildDependencies is different too. Webpack is object but Rspack is array.

    Yes, the rspack configuration is designed differently than webpack and will not be compatible with webpack.

    There are some reasons for this.

    1. The architecture of rspack cache is completely different from webpack, which makes some configurations meaningless on rspack, such as memoryCacheUnaffected.
    2. rspack cache needs to support more features in the future, such as remote cache.
  8. tats-u commented on Jan 21, 2025

    @tats-u
    ContributorAuthor

    https://rspack.dev/config/experiments#migrating-from-webpack-config

    You prepared a migration guide that covers all options used by Docusaurus, so it seems to be in acceptable range and we can try it once.

    module.exports = {
    - cache: {
    -   buildDependencies: {
    -     config: [__filename, path.join(__dirname, "package.json")],
    -     ts: [path.join(__dirname, "tsconfig.json")]
    -   }
    - },
      experiments: {
        cache: {
          type: "persistent",
    +     buildDependencies: [
    +       __filename,
    +       path.join(__dirname, "package.json"),
    +       path.join(__dirname, "tsconfig.json")
    +     ]
        },
      },
    };
    module.exports = {
    - cache: {
    -   name: `${config.name}-${config.mode}-${otherFlags}`,
    -   version: appVersion
    - },
      experiments: {
        cache: {
          type: "persistent",
    +     version: `${config.name}-${config.mode}-${otherFlags}-${appVersion}`
        },
      },
    };
  9. tats-u commented on Jan 26, 2025

    @tats-u
    ContributorAuthor

    /assets/images (imported images and images in Markdown) may not be created for builds after persistent cache is enabled and reused.

  10. tats-u commented on Jan 27, 2025

    @tats-u
    ContributorAuthor

    Does the persistent cache in Rspack save files generated by loaderContext.emitFile?

  11. jerrykingxyz commented on Jan 27, 2025

    @jerrykingxyz

    @tats-u Currently loaderContext.emitFile is not saved to persistent cache, we will support it in the next version. You can use loaderContext.cacheable = false to force rebuilding those module, of course this will cause some performance degradation.

  12. tats-u commented on Jan 27, 2025

    @tats-u
    ContributorAuthor

    @jerrykingxyz Thank you for your quick response. That must be why. Does "next version" mean 1.3 as of now?

  13. jerrykingxyz commented on Jan 27, 2025

    @jerrykingxyz

    I am actually working on fixing this right now, but it's a bit of work and will be included in version 1.2.3 on February 11th.

  14. tats-u commented on Jan 27, 2025

    @tats-u
    ContributorAuthor

    Oh, you are going to release that feature in the next patch version. Much earlier than I thought. I appreciate your continuous quick work.

  15. tats-u commented on Jan 27, 2025

    @tats-u
    ContributorAuthor

    Then we have to bump @rspack/core alpha to stable to accept that change in the near future.
    Looks like 1.2.2 works well with Docusaurus 3.7.

  16. tats-u commented on Jan 27, 2025

    @tats-u
    ContributorAuthor
  17. moonwalk47 commented on Feb 8, 2025

    @moonwalk47

    the more understanding i get about this the better it becomes
    thanks :-)

  18. slorber commented on Feb 11, 2025

    @slorber
    Collaborator

    Yes, I noted to ad a new Docusaurus Faster option once this gets released. Will work on it soon.

  19. slorber commented on Feb 21, 2025

    @slorber
    Collaborator

    I merged the persistent cache for v3.8

    However there is a bug in Rspack cache that prevents many of our files to be cached properly (all the code-generated files, notably all those in .docusaurus).

    I've documented this with benchmarks in #10931

    I hope that they fix it soon so that we can announce better benchmarks when releasing v3.8

  20. tats-u commented on Feb 21, 2025

    @tats-u
    ContributorAuthor

    Hooray!

    The bug you mention is web-infra-dev/rspack#9413.
    I wonder if it will have been fixed.

  21. slorber commented on Mar 7, 2025

    @slorber
    Collaborator

    The new API could help but doesn't really fix the bug in my opinion.

    See also my comment: web-infra-dev/rspack#9413 (comment)

    And extra repros I created to explain our problem better:

  22. slorber commented on Apr 18, 2025

    @slorber
    Collaborator

    The Rspack 1.3.6 upgrade will improve the performance of the persistent cache.

    Updated benchmarks available here: #11114

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

    proposal

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions