-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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
Turbopack: store serialized sourcemaps instead #75791
Conversation
Failing test suitesCommit: b24caae
Expand output● bigint API route support › development mode › should return 200
● bigint API route support › development mode › should return the BigInt result text
Read more about building and testing Next.js in contributing.md. |
Tests Passed |
Stats from current PRDefault BuildGeneral
Client Bundles (main, webpack)
Legacy Client Bundles (polyfills)
Client Pages
Client Build Manifests
Rendered Page Sizes
Edge SSR bundle Size
Middleware size
Next Runtimes
build cache
Diff detailsDiff for main-HASH.jsDiff too large to display |
8053c55
to
cd1830a
Compare
541aaf9
to
e21cf0f
Compare
a0e6698
to
2733c73
Compare
}; | ||
|
||
/// A mapping of byte-offset in the code string to an associated source map. | ||
pub type Mapping = (usize, Option<ResolvedVc<Box<dyn GenerateSourceMap>>>); | ||
pub type Mapping = (usize, Option<Rope>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub type Mapping = (usize, Option<Rope>); | |
pub type Mapping = (usize, Option<ResolvedVc<Rope>>); |
It would be better if we keep these Ropes in Vcs for better persistent caching. Otherwise it duplicates the data when serialized
#[derive(Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
struct SourceMapJson { | ||
version: u32, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
file: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
source_root: Option<String>, | ||
// Technically a required field, but we don't want to error here. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
sources: Option<Vec<Option<String>>>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
sources_content: Option<Vec<Option<String>>>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
names: Option<Vec<String>>, | ||
mappings: String, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
ignore_list: Option<Vec<u32>>, | ||
|
||
// A somewhat widespread non-standard extension | ||
debug_id: Option<String>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
sections: Option<Vec<SourceMapSectionItemJson>>, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of demanding this strict structure from the source map, you could deserialize it as serde_json::Value
and only pick the fields you are interested in and deserialize them with serde_json::from_value
.
@@ -391,7 +389,7 @@ pub struct CssChunkItemContent { | |||
pub import_context: Option<ResolvedVc<ImportContext>>, | |||
pub imports: Vec<CssImport>, | |||
pub inner_code: Rope, | |||
pub source_map: Option<ResolvedVc<ParseCssResultSourceMap>>, | |||
pub source_map: Option<Rope>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe store that as ResolvedVc too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds fine to merge and comments could be a follow up PR
Seems like this fixed |
#75791 made the sourcemap handling stricter, it caused this when encountering invalid input source maps (i.e. the ones that are published to npm). Let's keep the old behavior for now (which is also what Webpack does). ``` Caused by: 0: Execution of run_inner_operation failed 1: Execution of run_test_operation failed 2: Execution of ModuleGraph::from_modules failed 3: Execution of SingleModuleGraph::new_with_entries failed 4: [project]/turbopack/crates/turbopack-tests/tests/snapshot/source_maps/invalid/input/index.js [test] (ecmascript) 5: Execution of primary_chunkable_referenced_modules failed 6: Execution of <EcmascriptModuleAsset as Module>::references failed 7: Execution of analyse_ecmascript_module failed 8: failed to analyse ecmascript module '[project]/turbopack/crates/turbopack-tests/tests/snapshot/source_maps/invalid/input/index.js [test] (ecmascript)' 9: Execution of <SourceMapReference as GenerateSourceMap>::generate_source_map failed 10: invalid type: string "use client", expected struct SourceMapJson at line 1 column 12 ```
Store sourcemaps JSON-serialized (as opposed to structs containing arrays of decoded mappings), which is more memory efficient (and the main operation we perform is concatenation anyway, lookups are only used for error message locations)
This will also deduplicate sourcemaps (because cloning a
Rope
is just a reference-counted pointer).Closes PACK-3947