Skip to content

perf: avoid generating hires sourcemap for original input code #5062

@sapphi-red

Description

@sapphi-red

A hires sourcemap is generated here for #3107.

// If sourcemap is empty and code has changed, need to create one remapping original code.
// Here using `hires: true` to get more accurate column information, but it has more overhead.
// TODO: maybe it should be add a option to control hires.
let magic_string = MagicString::new(original_code);
Some(magic_string.source_map(SourceMapOptions {
hires: string_wizard::Hires::True,
include_content: true,
source: id.into(),
}))

Generating hires sourcemap is costly in terms of memory as it contains many mappings.

But this we can avoid that by improving collapse_sourcemaps.

pub fn collapse_sourcemaps(mut sourcemap_chain: Vec<&SourceMap>) -> SourceMap {

Rollup does not use hires sourcemaps and have some additional code to handle these cases in getCollapsedSourcemap.
https://github.com/rollup/rollup/blob/37d1915060e08b84326bee0713444eec7162de88/src/utils/collapseSourcemaps.ts#L190-L203

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions