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: cache parsed source maps to reduce memory footprint #46225

Merged

Conversation

legendecas
Copy link
Member

This also improves performance to map the stack trace when the Error.stack is accessed.

                                                      confidence improvement accuracy (*)   (**)  (***)
es/error-stack.js n=100000 method='sourcemap'                ***     18.90 %       ±1.54% ±2.06% ±2.68%
es/error-stack.js n=100000 method='without-sourcemap'                -0.24 %       ±1.40% ±1.86% ±2.43%

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

Fixes #46140.

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Jan 16, 2023
@legendecas legendecas added lib / src Issues and PRs related to general changes in the lib or src directory. source maps Issues and PRs related to source map support. labels Jan 16, 2023
This also improves performance to map the stack trace when the
`Error.stack` is accessed.
@aduh95
Copy link
Contributor

aduh95 commented Jan 17, 2023

Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1292/

Results
                                                      confidence improvement accuracy (*)   (**)  (***)
es/error-stack.js n=100000 method='sourcemap'                ***     18.20 %       ±2.28% ±3.04% ±3.96%
es/error-stack.js n=100000 method='without-sourcemap'                 1.24 %       ±3.05% ±4.06% ±5.29%

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

@legendecas legendecas added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 17, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 17, 2023
@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 17, 2023
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

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

LGTM but I'm somewhat baffled by that ObjectGetValueSafe() function. What's its purpose?

If it's to protect against someone users monkey-patching Object.prototype, wouldn't it be better/simpler/more efficient to use symbols instead of named properties?

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Jan 22, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jan 22, 2023
@nodejs-github-bot nodejs-github-bot merged commit 651c09c into nodejs:main Jan 22, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in 651c09c

@legendecas legendecas deleted the source-map/memory-footprint branch January 24, 2023 16:08
@legendecas
Copy link
Member Author

LGTM but I'm somewhat baffled by that ObjectGetValueSafe() function. What's its purpose?

If it's to protect against someone users monkey-patching Object.prototype, wouldn't it be better/simpler/more efficient to use symbols instead of named properties?

Thanks for pointing this out. I'll submit a follow-up PR to make those plain objects to be null-prototyped so that we can get rid of ObjectGetValueSafe.

ruyadorno pushed a commit that referenced this pull request Feb 1, 2023
This also improves performance to map the stack trace when the
`Error.stack` is accessed.

PR-URL: #46225
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@ruyadorno ruyadorno mentioned this pull request Feb 1, 2023
@joelmukuthu
Copy link

joelmukuthu commented Feb 24, 2023

Hi all, I see this has so far only been released in v19.6.0. What's the process to get it released on the v18 branch? FYI there's still an active bug in v18 that this fix attempts to address.

@juanarbol juanarbol added the backport-blocked-v18.x PRs that should land on the v18.x-staging branch but are blocked by another PR's pending backport. label Mar 3, 2023
@juanarbol
Copy link
Member

This uses getCjsSourceMapCache, which was introduced in #45849 and labeled as backport-blocked-v18.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backport-blocked-v18.x PRs that should land on the v18.x-staging branch but are blocked by another PR's pending backport. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. source maps Issues and PRs related to source map support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory usage spikes with source maps (--enable-source-maps) from v18.10.0 onwards
8 participants