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,src: add source map support for global eval #43428

Closed
wants to merge 2 commits into from

Conversation

legendecas
Copy link
Member

Add source map support for global eval.

Dynamic sources with FunctionConstructor are not supported yet as
V8 prepends lines to the sources which makes the stack line number
incorrect.

Refs: #43047

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. 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 Jun 14, 2022
@legendecas legendecas marked this pull request as ready for review June 14, 2022 17:06
@legendecas legendecas added the source maps Issues and PRs related to source map support. label Jun 14, 2022
@legendecas legendecas requested a review from bcoe June 14, 2022 17:41
@legendecas legendecas added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 16, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 16, 2022
@nodejs-github-bot
Copy link
Collaborator

@bcoe
Copy link
Contributor

bcoe commented Jun 20, 2022

@legendecas awesome, will work on reviewing soon.

CC: @nodejs/cpp-reviewers

@bcoe
Copy link
Contributor

bcoe commented Jul 1, 2022

@legendecas I have a 4 day weekend, hoping to get through my backlog of reviews.

Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

I love this, much simpler implementation than I would have guessed.

src/node_errors.cc Show resolved Hide resolved
bool codegen_allowed =
allow_code_gen->IsUndefined() || allow_code_gen->IsTrue();
return {
codegen_allowed,
Copy link
Contributor

Choose a reason for hiding this comment

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

If no callback is provided, is codegen_allowed just always truthy?

Copy link
Member Author

Choose a reason for hiding this comment

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

If the value set in v8::Context::AllowCodeGenerationFromStrings is true, no host-callbacks are called on compiling dynamic sources.

The callback is called only when AllowCodeGenerationFromStrings(false) is set on the context. Thus if the callback is not provided when AllowCodeGenerationFromStrings is set to false, no dynamic sources are allowed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Prior to this, did v8::Context::AllowCodeGenerationFromStrings default to true?

Any concerns about performance hits we might observe now that we're calling a handler? Perhaps it would be worth adding a benchmark?

Copy link
Member Author

@legendecas legendecas Jul 7, 2022

Choose a reason for hiding this comment

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

@bcoe thank you for your suggestion. I added a new fast-path on if sourcemap is enabled in ModifyCodeGenerationFromStrings and ran a benchmark against the main branch. Now the difference when sourcemap is not enabled can be slight if the dynamic code is not trivial.

However, with sourcemap enabled, the difference can be significant. But I suppose this is acceptable since sourcemap comes with costs.

                                                confidence improvement accuracy (*)   (**)  (***)
es/eval.js n=1000000 method='without-sourcemap'        ***     -1.54 %       ±0.36% ±0.49% ±0.63%
es/eval.js n=1000000 method='sourcemap'        ***    -31.90 %       ±1.41% ±1.89% ±2.49%

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for adding the benchmark 👌

I'm curious, how much more does it slow down if you have the noop closure, without the fast path?

However, with sourcemap enabled, the difference can be significant. But I suppose this is acceptable since sourcemap comes with costs.

I think this is to be expected. Unrelated to this PR, I'm becoming convinced we should stop performing the logic that loads the original source from disk for providing visual context, as I believe this is one of the major slow downs.

Copy link
Member Author

Choose a reason for hiding this comment

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

The slowdown can be up to ~25% without the fast path with this micro benchmark.

I think this is to be expected. Unrelated to this PR, I'm becoming convinced we should stop performing the logic that loads the original source from disk for providing visual context, as I believe this is one of the major slow downs.

Yeah, when sourcemap support is not enabled, the visual context is not prepended to the value of the stack property. It's just being prepended when the error is being printed by the runtime like fatal exceptions. While accessing stack property is one of the most commonly used paths, improving the performance of it is always a good motivation. Are you planning to work on it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you planning to work on it?

I don't think I'll have cycles to work on this in the short term, I'll CC you on the pertinent issue.

@bcoe
Copy link
Contributor

bcoe commented Jul 5, 2022

@legendecas rebase and let's see about landing this?

@legendecas legendecas added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 6, 2022
@legendecas
Copy link
Member Author

@bcoe thank you for the review. updated :)

@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 6, 2022
@legendecas legendecas force-pushed the issue-43047 branch 3 times, most recently from 5f49aaa to 9c28953 Compare July 7, 2022 17:36
Dynamic sources with FunctionConstructor is not supported yet as
V8 prepends lines to the sources which makes the stack line number
incorrect.
@legendecas legendecas added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 8, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 8, 2022
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

legendecas added a commit that referenced this pull request Jul 11, 2022
Dynamic sources with FunctionConstructor is not supported yet as
V8 prepends lines to the sources which makes the stack line number
incorrect.

PR-URL: #43428
Refs: #43047
Reviewed-By: Ben Coe <[email protected]>
@legendecas
Copy link
Member Author

Landed in 02eb10b

@legendecas legendecas closed this Jul 11, 2022
@legendecas legendecas deleted the issue-43047 branch July 11, 2022 13:44
targos pushed a commit that referenced this pull request Jul 12, 2022
Dynamic sources with FunctionConstructor is not supported yet as
V8 prepends lines to the sources which makes the stack line number
incorrect.

PR-URL: #43428
Refs: #43047
Reviewed-By: Ben Coe <[email protected]>
targos pushed a commit that referenced this pull request Jul 31, 2022
Dynamic sources with FunctionConstructor is not supported yet as
V8 prepends lines to the sources which makes the stack line number
incorrect.

PR-URL: #43428
Refs: #43047
Reviewed-By: Ben Coe <[email protected]>
codebytere added a commit to electron/electron that referenced this pull request Aug 24, 2022
codebytere added a commit to electron/electron that referenced this pull request Aug 25, 2022
jkleinsc pushed a commit to electron/electron that referenced this pull request Aug 29, 2022
* chore: bump node in DEPS to v16.17.0

* chore: fixup asar patch

* lib: use null-prototype objects for property descriptors

nodejs/node#43270

* src: make SecureContext fields private

nodejs/node#43173

* crypto: remove Node.js-specific webcrypto extensions

nodejs/node#43310

* test: refactor to top-level await

nodejs/node#43500

* deps: cherry-pick two libuv fixes

nodejs/node#43950

* src: slim down env-inl.h

nodejs/node#43745

* util: add AggregateError.prototype.errors to inspect output

nodejs/node#43646

* esm: improve performance & tidy tests

nodejs/node#43784

* src: NodeArrayBufferAllocator delegates to v8's allocator

nodejs/node#43594

* chore: update patch indices

* chore: update filenames

* src: refactor IsSupportedAuthenticatedMode

nodejs/node#42368

* src: add --openssl-legacy-provider option

nodejs/node#40478

* lib,src: add source map support for global eval

nodejs/node#43428

* trace_events: trace net connect event

nodejs/node#43903

* deps: update ICU to 71.1

nodejs/node#42655

This fails the test because it's missing https://chromium-review.googlesource.com/c/chromium/deps/icu/+/3841093

* lib: give names to promisified exists() and question()

nodejs/node#43218

* crypto: add CFRG curves to Web Crypto API

nodejs/node#42507

* src: fix memory leak for v8.serialize

nodejs/node#42695

This test does not work for Electron as they do not use V8's
ArrayBufferAllocator.

* buffer: fix atob input validation

nodejs/node#42539

* src: fix ssize_t error from nghttp2.h

nodejs/node#44393

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <[email protected]>
guangwong pushed a commit to noslate-project/node that referenced this pull request Oct 10, 2022
Dynamic sources with FunctionConstructor is not supported yet as
V8 prepends lines to the sources which makes the stack line number
incorrect.

PR-URL: nodejs/node#43428
Refs: nodejs/node#43047
Reviewed-By: Ben Coe <[email protected]>
khalwa pushed a commit to solarwindscloud/electron that referenced this pull request Feb 22, 2023
* chore: bump node in DEPS to v16.17.0

* chore: fixup asar patch

* lib: use null-prototype objects for property descriptors

nodejs/node#43270

* src: make SecureContext fields private

nodejs/node#43173

* crypto: remove Node.js-specific webcrypto extensions

nodejs/node#43310

* test: refactor to top-level await

nodejs/node#43500

* deps: cherry-pick two libuv fixes

nodejs/node#43950

* src: slim down env-inl.h

nodejs/node#43745

* util: add AggregateError.prototype.errors to inspect output

nodejs/node#43646

* esm: improve performance & tidy tests

nodejs/node#43784

* src: NodeArrayBufferAllocator delegates to v8's allocator

nodejs/node#43594

* chore: update patch indices

* chore: update filenames

* src: refactor IsSupportedAuthenticatedMode

nodejs/node#42368

* src: add --openssl-legacy-provider option

nodejs/node#40478

* lib,src: add source map support for global eval

nodejs/node#43428

* trace_events: trace net connect event

nodejs/node#43903

* deps: update ICU to 71.1

nodejs/node#42655

This fails the test because it's missing https://chromium-review.googlesource.com/c/chromium/deps/icu/+/3841093

* lib: give names to promisified exists() and question()

nodejs/node#43218

* crypto: add CFRG curves to Web Crypto API

nodejs/node#42507

* src: fix memory leak for v8.serialize

nodejs/node#42695

This test does not work for Electron as they do not use V8's
ArrayBufferAllocator.

* buffer: fix atob input validation

nodejs/node#42539

* src: fix ssize_t error from nghttp2.h

nodejs/node#44393

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <[email protected]>
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. c++ Issues and PRs that require attention from people who are familiar with C++. 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.

4 participants