Skip to content

perf: Only extract source map comments at the end of the file#18039

Merged
nicolo-ribaudo merged 2 commits into
babel:mainfrom
liuxingbaoyu:perf-input-map
Jun 16, 2026
Merged

perf: Only extract source map comments at the end of the file#18039
nicolo-ribaudo merged 2 commits into
babel:mainfrom
liuxingbaoyu:perf-input-map

Conversation

@liuxingbaoyu

@liuxingbaoyu liuxingbaoyu commented May 31, 2026

Copy link
Copy Markdown
Member
Q                       A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT
  1. Only search for the input source map when source maps are needed.
  2. Only search the top-level source map.
  3. Print an error log when loading fails.

Potential impact:
Currently, if users do not enable sourceMaps, source map comments in the code will be retained.
If some tools directly concatenate the source code and map within functions, they will no longer be loaded. (However, we only load one source map anyway.)

This greatly improves core performance: ~20%

PS F:\babel\benchmark\babel-core\real-case-preset-env-typescript> node .\babel-parser-tokenizer-index.mjs         
current: 86.54 ops/sec ±1.7% (12ms)
PS F:\babel\benchmark\babel-core\real-case-preset-env-typescript> node .\babel-parser-tokenizer-index.mjs
current: 104 ops/sec ±1.38% (9.587ms)

Closes #16874

@liuxingbaoyu liuxingbaoyu added PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories pkg: core area: sourcemaps labels May 31, 2026
@babel-bot

babel-bot commented May 31, 2026

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61771

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9980eb58c5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/babel-core/src/transformation/normalize-file.ts
@pkg-pr-new

pkg-pr-new Bot commented May 31, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: 022060e

@nicolo-ribaudo nicolo-ribaudo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically if a source map comment is followed by code we should ignore it.

So it should be enough to scan from the end, and only the trailing comments.

Maybe we could even start doing it at the parser level at some point.

https://tc39.es/ecma426/#sec-JavaScriptExtractSourceMapURL

@nicolo-ribaudo nicolo-ribaudo added PR: Spec Compliance 👓 A type of pull request used for our changelog categories PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories and removed PR: Needs Docs PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories labels Jun 14, 2026
@nicolo-ribaudo nicolo-ribaudo changed the title perf: Improve the performance of processing source maps perf: Only extract source map comments at the end of the file Jun 14, 2026
@nicolo-ribaudo

Copy link
Copy Markdown
Member

@liuxingbaoyu I pushed a commit to further limit which comments we look at, so that we match the spec :)

@nicolo-ribaudo nicolo-ribaudo merged commit b71c35a into babel:main Jun 16, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: sourcemaps pkg: core PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories PR: Spec Compliance 👓 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants