perf(remix-dev/vite): extract route module exports in parallel for route manifest generation + use transformRequest
to utilize vite's transform cache
#8102
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(These two ideas are independent, so we can evaluate separately. For initial testing, I pushed in one PR, but I'll create two PRs separately later)
1st idea
Not properly tested or benchmarked yet, but it seems doing
await getRouteModuleExports(...)
in for loop slow down server start up, so I'm experimenting with doingPromise.all
instead.(Regarding this, I was initially looking at
server.warmup
option https://vitejs.dev/config/server-options#server-warmup, but what it does is more-or-less just triggeringtransformRequest
in parallel (code) and actuallyserver.warmup
won't be triggered for child compiler use cases, so I didn't think further about this option.)2nd idea
Also, while looking at
getRouteModuleExports
, I thought it might be beneficial to useViteDevServer.transformRequest
API instead of manually transforming code viaPluginContainer
API. Currently, I neededexperimental.skipSsrTransform
to make it work, but I also have another idea to not rely on that (see TODO in the code).Again I haven't tested properly yet, but I'm hoping this might allow utilizing vite's cache (+ auto invalidation?) to save unnecessary transform.
If this idea is sound, then remix's own caching introduced in #7908 to reduce virtual entry invalidation might not be necessary since I think the bottleneck is
getDevManifest
transforming all route files to extract all exports.To be able to analyze and evaluate perf ideas more systematically, I'm thinking to prepare dummy remix app with many routes and components. For example, It would be something like remix-equivalent of these benchmarks: