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

Add caching around resolvePluginConfig() and only invalidate virtual modules when necessary #7908

Merged
merged 3 commits into from
Nov 5, 2023

Conversation

dmarkow
Copy link
Contributor

@dmarkow dmarkow commented Nov 4, 2023

Closes: #7868. This adds caching around resolvePluginConfig() to avoid recalculating routes hundreds of times on startup. There is one cache used for remix-react-refresh-babel and remix-remove-server-exports, and another used in the middleware to determine if the virtual modules need to be invalidated.

I was unable to get a single cache working, as the cache would get updated in one of the other plugin transforms so there was no way to tell if it was stale for the route request by the time the middleware ran.

  • Docs
  • Tests: All existing Vite integration tests are passing with these changes

Testing Strategy:

Discussion with @pcattori, "we have pretty good tests for this sort of thing in integration/vite-dev-express-test so if those pass with your changes I'd be reasonably confident about it"

Also used this in developing our app the last couple of days, which included changing #and adding new routes and lots of HMR/HDR. I didn't run into a single stale cache issue with HMR/HDR, and performance was a ton better than 2.2.0 as released.

Benchmarking

On 2.2.0, my app startup took 24 seconds, HMR took 2+ seconds when there was a loader, and basic site navigation took around 2 seconds.

With the patch, app startup is just under 12 seconds and HMR with loaders and site nav are both around 400ms. (Note that some, but not all, of this improvement is due to the LiveReload logic fix added since 2.2.0).

Not profiled below, but my vite build && vite build --ssr times dropped from a combined 129 seconds to 24 seconds.

2.2.0:

CleanShot 2023-11-04 at 09 13 44@2x
CleanShot 2023-11-04 at 09 14 12@2x
CleanShot 2023-11-04 at 09 14 35@2x

Patched:

CleanShot 2023-11-04 at 09 14 53@2x
CleanShot 2023-11-04 at 09 15 09@2x
CleanShot 2023-11-04 at 09 15 21@2x

Copy link

changeset-bot bot commented Nov 4, 2023

🦋 Changeset detected

Latest commit: cafa886

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@remix-run/dev Patch
create-remix Patch
remix Patch
@remix-run/architect Patch
@remix-run/cloudflare Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
@remix-run/css-bundle Patch
@remix-run/deno Patch
@remix-run/eslint-config Patch
@remix-run/express Patch
@remix-run/node Patch
@remix-run/react Patch
@remix-run/serve Patch
@remix-run/server-runtime Patch
@remix-run/testing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@markdalgleish markdalgleish left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@markdalgleish markdalgleish merged commit 903268f into remix-run:dev Nov 5, 2023
9 checks passed
@markdalgleish
Copy link
Member

Also, thanks for the help, and for being so thorough! I really appreciate it.

@ZipBrandon
Copy link

@markdalgleish I'm using 0.0.0-nightly-903268f-20231106 and confirm that I'm back to 20s build times from 5m45 seconds. Thank you for getting this in and for @dmarkow authoring!

Copy link
Contributor

🤖 Hello there,

We just published version 2.3.0-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

🤖 Hello there,

We just published version 2.3.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants