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

Cache module info getters before output generation #5438

Merged
merged 7 commits into from Mar 28, 2024

Conversation

bluwy
Copy link
Contributor

@bluwy bluwy commented Mar 22, 2024

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

Description

According to this.getModuleInfo:

During the build, this object represents currently available information about the module which may be inaccurate before the buildEnd hook

After that, during the output generation phase, the props will no longer change and are stable. However, the internal implementation still keeps them as getters, so there's a cost later even if they don't change.

This PR implements caching for the getters after the build ends (or specifically at the start of output generation). This way accessing the module info will be fast.


Usage in the wild:

  1. Vite reads the module graph to analyze ineffective dynamic imports (This could actually be nice if supported natively in Rollup)
  2. Astro walks the module graph for CSS and scripts analysis.

I was measuring the perf for https://github.com/withastro/docs, and with this PR, the Rollup build time dropped from 3m30s to 3m.


I'm not sure how to write a test for cache effectiveness, but I tested manually that the caching works. Existing tests should also pass.

Copy link

vercel bot commented Mar 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rollup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 28, 2024 5:51am

Copy link

codecov bot commented Mar 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.80%. Comparing base (fffaede) to head (38c0027).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5438   +/-   ##
=======================================
  Coverage   98.80%   98.80%           
=======================================
  Files         236      237    +1     
  Lines        9423     9432    +9     
  Branches     2398     2398           
=======================================
+ Hits         9310     9319    +9     
  Misses         48       48           
  Partials       65       65           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/utils/getter.ts Outdated Show resolved Hide resolved
src/Module.ts Outdated Show resolved Hide resolved
Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

src/utils/getter.ts Outdated Show resolved Hide resolved
Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

I have taken the liberty to add the last change I proposed. From my side, this looks good now and we can merge and release it later today.

@lukastaegert lukastaegert added this pull request to the merge queue Mar 28, 2024
Merged via the queue into rollup:master with commit 41ba566 Mar 28, 2024
29 checks passed
@bluwy bluwy deleted the cache-module-info-getters branch March 28, 2024 13:36
@bluwy
Copy link
Contributor Author

bluwy commented Mar 28, 2024

No problem and thanks! I didn't see your comment on mobile, but the change is fine by me too.

Copy link

This PR has been released as part of rollup@4.13.2. You can test it via npm install rollup.

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

3 participants