Skip to content
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

lib: skip source maps in node_modules #56639

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Jan 17, 2025

Skipping source maps in node_modules by default improves the general
performance. Add module.setSourceMapsSupport(enabled, options) to
enable source maps in node_modules if it is needed. This moves
all source maps related API to node:module and this a step to
promote the source maps API to stable.

Files in node_modules are not authored by the user directly and the
original sources are less relevant to the user.

Micro-benchmark result:

                                                          confidence improvement accuracy (*)   (**)  (***)
es/error-stack.js n=100000 method='sourcemap-with-node-modules'  ***     27.04 %       ±1.50% ±2.00% ±2.60%
es/error-stack.js n=100000 method='sourcemap'                    ***     -5.01 %       ±1.08% ±1.43% ±1.86%
es/error-stack.js n=100000 method='without-sourcemap'            ***      1.98 %       ±0.94% ±1.26% ±1.65%

Be aware that when doing many comparisons the risk of a false-positive result increases.
In this case, there are 4 comparisons, you can thus expect the following amount of false-positive results:
  0.20 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.04 false positives, when considering a   1% risk acceptance (**, ***),
  0.00 false positives, when considering a 0.1% risk acceptance (***)

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/performance
  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jan 17, 2025
@legendecas legendecas added source maps Issues and PRs related to source map support. and removed lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jan 17, 2025
@legendecas legendecas force-pushed the source-maps/node_modules branch 2 times, most recently from fb1a57e to cfc1fd9 Compare January 17, 2025 11:58
@legendecas legendecas marked this pull request as ready for review January 17, 2025 12:00
Comment on lines +1598 to +1599
* `nodeModules` {boolean} If enabling the support for files in `node_modules`.
* `generatedCode` {boolean} If enabling the support for generated code from `eval` or `new Function`.
Copy link
Member

Choose a reason for hiding this comment

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

It's missing doc for default values I think

validateBoolean(enabled, 'enabled');
validateObject(options, 'options');

const { nodeModules = false, generatedCode = false } = options;
Copy link
Member

Choose a reason for hiding this comment

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

In the past, we always enabled the source map for nodeModules right? If so, having the default values to false won't be a breaking change? Maybe having this as true will be better if the my first assumption is right.

Comment on lines +52 to +53
nodeModules: false,
generatedCode: false,
Copy link
Member

Choose a reason for hiding this comment

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

Same for this one, this is probably breaking change if we keep false.

Skipping source maps in `node_modules` by default improves the general
performance. Add `module.setSourceMapsSupport(enabled, options)` to
enable source  maps in `node_modules` if it is needed. This moves
all source maps related API to `node:module` and this a step to
promote the source maps API to stable.

Files in `node_modules` are not authored by the user directly and the
original sources are less relevant to the user.
@legendecas legendecas force-pushed the source-maps/node_modules branch from cfc1fd9 to 94667aa Compare January 17, 2025 12:51
Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

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

Considering many enable source maps via --enable-source-maps I think it also warrants something like --disable-source-maps-in-node-modules or some other flag with a better name? Otherwise end users have to preload a script that invokes the API which is a bit of a hassle. We can set it to false by default for existing releases and in the next major release, flip it to true.

Copy link

codecov bot commented Jan 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.21%. Comparing base (0e7ec5e) to head (94667aa).
Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #56639   +/-   ##
=======================================
  Coverage   89.20%   89.21%           
=======================================
  Files         662      662           
  Lines      191890   191896    +6     
  Branches    36928    36938   +10     
=======================================
+ Hits       171176   171194   +18     
+ Misses      13554    13542   -12     
  Partials     7160     7160           
Files with missing lines Coverage Δ
lib/internal/bootstrap/node.js 99.57% <100.00%> (+<0.01%) ⬆️
lib/internal/modules/esm/module_job.js 99.25% <100.00%> (ø)
lib/internal/process/pre_execution.js 91.70% <100.00%> (ø)
lib/module.js 100.00% <100.00%> (ø)

... and 32 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
source maps Issues and PRs related to source map support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants