Skip to content

perf(build): skip unchanged sourcemaps - #4925

Merged
pi0 merged 5 commits into
nitrojs:mainfrom
onmax:perf/sourcemap-writeback
Oct 26, 2026
Merged

pi0 merged 5 commits into
nitrojs:mainfrom
onmax:perf/sourcemap-writeback

Conversation

@onmax

@onmax onmax commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🔗 Linked issue

No issue.

❓ Type of change

  • 👌 Enhancement (improving an existing functionality like performance)

📚 Description

nitro:sourcemap used to set asset.source on every .map file, even when nothing changed. Rolldown counts each assignment as an update and copies the map back from JS.

On the Rolldown and Vite builders, something always changed anyway: their maps included sourcesContent, and the hook deleted it.

This PR:

  • Makes nitro:sourcemap write back only the maps it actually changes (renamed virtual sources, or removed sourcesContent / x_google_ignoreList / mappings).
  • Sets sourcemapExcludeSources on the Rolldown and Vite (Rolldown) builders when nitro:sourcemap would strip sourcesContent anyway: production builds with sourcemap on and experimental.sourcemapMinify not false. The Rollup builders already set it.
    • With sourcemapMinify: false, or in dev, maps keep sourcesContent as before.
    • An explicit rolldownConfig.output.sourcemapExcludeSources still applies.

On a Nuxt app with about 3,600 server chunks, the Nitro build used about 0.2 s less main-thread CPU.

Output

Emitted files are unchanged. A small app (routes, inlined node_modules deps, virtual modules) was built before and after this PR on the rollup, rolldown and vite builders, each with and without sourcemapMinify: false. Once local paths are normalized, all .mjs and .map files match.

Behavior notes

The Rolldown and Vite builders now match the Rollup builder in two cases:

  • A plugin that reads sourcesContent before nitro:sourcemap runs (buildPlugins with enforce: "pre", rolldownConfig.plugins, Vite plugins in generateBundle), or one that reads chunk.map, no longer sees it. Tools that read the written .map files (writeBundle or later) are not affected, since those never had sourcesContent.
  • If rolldownConfig.output.sourcemap is overridden to "inline", inline maps no longer include sourcesContent. nitro:sourcemap never processed inline maps.

To keep sourcesContent, set experimental.sourcemapMinify: false.

@onmax
onmax requested a review from pi0 as a code owner October 25, 2026 17:39
@vercel

vercel Bot commented Oct 25, 2026

Copy link
Copy Markdown

@onmax is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3ca8a5f3-b023-4ee0-94f5-eddc9d688b79
Commits

Reviewing files that changed from the base of the PR and between e6db803 and f557c7d.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 80d1f72d-c75a-4673-8dad-d323c014c08a
Commits

Reviewing files that changed from the base of the PR and between 9402f34 and 064eed9.

Files selected for processing: 1
  • test/unit/sourcemap.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Both Rolldown output configurations now set sourcemap source exclusion from sourcemap settings and build mode. The sourcemap plugin updates map fields and serializes assets only when processing changes a map. Tests cover both behaviors.

Changes: Sourcemap handling

Layer / File(s) Summary
Configure sourcemap source exclusion
src/build/plugins/sourcemap.ts, src/build/rolldown/config.ts, src/build/vite/bundler.ts, test/unit/sourcemap.test.ts
A shared helper determines when sourcemap sources are excluded. Both Rolldown configurations use the helper, and tests cover the settings and explicit user configuration.
Conditionally rewrite sourcemaps
src/build/plugins/sourcemap.ts, test/unit/sourcemap.test.ts
The plugin updates map fields and serializes the map only when processing changes it. Tests check that unchanged maps do not trigger the asset source setter.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Merge Risk: Minimal · up to 064ee

No actionable merge-blocking risk was identified in the sourcemap changes.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title follows Conventional Commits syntax with the type perf, scope build, and a subject that accurately describes the main sourcemap performance change.
Description check Passed The description clearly explains the sourcemap optimization, configuration changes, compatibility behavior, tests, and reported performance impact.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4925

commit: f557c7d

@pi0
pi0 merged commit 098ab72 into nitrojs:main Oct 26, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants