turbopack: cache TransformPlugin in narrow-scoped turbo-tasks functions#92842
Merged
Conversation
…nvalidation TransformPlugin is not serializable and not comparable. When celled inline via ResolvedVc::cell(Box::new(...)), it causes invalidation of all dependent tasks. Move each TransformPlugin creation into its own #[turbo_tasks::function] so that Vc<TransformPlugin> is cached and reused across task invocations. Co-Authored-By: Claude <noreply@anthropic.com>
- Introduce `JsonValue` newtype wrapping `serde_json::Value` with manual
`Hash` + `TaskInput` impls so `serde_json::Value` can be used as a
turbo-tasks function argument; use it to properly cache the SWC wasm
plugin transform via a `#[turbo_tasks::function]`
- Replace the `bool` roundtrip in `next_strip_page_exports` with
`ExportFilterInput` enum (derives `TaskInput`) mirroring `ExportFilter`,
eliminating the silent fallback risk when a new variant is added
- Derive `TaskInput` on `ActionsTransform` and pass it directly to the
turbo-tasks function instead of converting through `is_server: bool`
- Replace all `.expect("... config must exist")` panics in option-gated
plugin functions with `.context(...)?` for proper error propagation
- Restore blank line before `Ok(())` in `modularize_imports`
- Add `// TODO: use get_ecma_transform_rule instead` comments to the 10
transform functions that manually inline the same `ModuleRule::new` +
`ExtendEcmascriptTransforms` pattern
Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Tests Passed |
Merging this PR will improve performance by 3.91%
Performance Changes
Comparing Footnotes
|
Contributor
Stats from current PR✅ No significant changes detected📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URL |
mischnic
reviewed
Apr 15, 2026
mischnic
reviewed
Apr 15, 2026
- Fix trailing space typo in Middleware row of RSC context table - Use ResolvedVc<RcStr> and ResolvedVc<CacheKinds> directly as parameters in next_server_actions_transform_plugin, avoiding .to_resolved().await? inside the function body Co-Authored-By: Claude <noreply@anthropic.com>
mischnic
approved these changes
Apr 15, 2026
This was referenced Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What?
Refactor all usages of
EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(...) as _))acrossnext-coreandturbopack-testsso thatTransformPlugincells are created inside dedicated#[turbo_tasks::function]functions rather than inline at call sites.Additionally:
JsonValuenewtype wrappingserde_json::Valuethat implementsTaskInput, enabling the SWC wasm plugin list to be passed through a turbo-tasks function boundary and properly cached.boolroundtrip innext_strip_page_exportswith anExportFilterInputenum that derivesTaskInput, mirroringExportFilterexhaustively (so a new upstream variant is a compile error, not a silent fallback).TaskInputonActionsTransformand pass it directly to the cached function instead of converting tois_server: boolat the call site..expect("... config must exist")panics in option-gated plugin functions (emotion,styled_components,react_remove_properties,remove_console,relay) with.context(...)?for proper error propagation.// TODO: use get_ecma_transform_rule insteadcomments to the ~10 transform functions that manually inline the sameModuleRule::new+ExtendEcmascriptTransformspattern thatget_ecma_transform_ruleabstracts.Why?
TransformPluginis not serializable and not comparable. When aTransformPluginiscelled inline (i.e.ResolvedVc::cell(Box::new(...) as _)) inside a turbo-tasks function, a new cell is created on every invocation of the enclosing function, because the framework has no way to detect that the value is the same as before. This causes every task that depends on theTransformPlugincell to be invalidated unnecessarily.By moving the
Vc::cell(...)call into its own narrow-scoped#[turbo_tasks::function], turbo-tasks can cache the cell by the function's inputs. If the inputs haven't changed, the function won't re-run, the existing cell is reused, and downstream tasks are not invalidated.How?
Each inline
ResolvedVc::cell(Box::new(SomeTransformer { ... }) as _)is replaced with:Where a cached function needs to store a
ResolvedVcin the resulting transformer struct, the parameter is declared asResolvedVc<T>directly in the#[turbo_tasks::function]signature. The turbo_tasks macro rewritesResolvedVc<T>→Vc<T>in the external call-site signature, and the call site passes a dereferenced*resolved_vc. This avoids a redundant.to_resolved().await?inside the function body.For the SWC wasm plugin case,
serde_json::Value(used for per-plugin config) doesn't implementHashorTaskInput. AJsonValuenewtype is introduced with:#[bincode(with = "turbo_bincode::serde_self_describing")]for serializationHashimpl that hashes the JSON string representationTaskInputimpl (is_transient = falsesince the type contains noVcs)