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

Ensure using the nodejs source-map support #2448

Merged
merged 1 commit into from
Feb 17, 2021

Conversation

joeljeske
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Performance enhancement

What is the current behavior?

Issue Number: N/A

What is the new behavior?

When using libraries like js-dom that provide a browser-like api inside nodejs, the source map support can be tricked into thinking that it is running in a browsers, which will attempt to use XMLHttpRequest instead of require('fs'). Depending on implementation of the XMLHttpRequest (presumably loaded by js-dom or alternative), this can be much slower to load source maps from disk, causing a higher latency run of nodejs.

Even if the user is using a browser-like experience within nodejs, the nodejs implementation of source map support should always be superior, thus we should hint to the source map support to always use the nodejs fs module to load source maps.

For me, I noticed this slow down in test runs, and found an 80% speedup across some runs. Other's mileage may vary.

Does this PR introduce a breaking change?

  • Yes
  • No

When using libraries like js-dom that provide a browser-like api inside nodejs, the source map support can be tricked into thinking that it is running in a browsers, which will attempt to use `XMLHttpRequest` instead of `require('fs')`. Depending on implementation of the XMLHttpRequest (presumably loaded by js-dom or alternative), this can be much slower to load source maps from disk, causing a higher latency run of nodejs. 

Even if the user is using a browser-like experience within nodejs, the nodejs implementation of source map support should always be superior, thus we should hint to the source map support to always use the nodejs fs module to load source maps. 

For me, I noticed this slow down in test runs, and found an 80% speedup across some runs. Other's mileage may vary.
@mattem
Copy link
Collaborator

mattem commented Feb 12, 2021

Thanks. Windows failure looks like a flake, rebase to rerun?

@alexeagle
Copy link
Collaborator

Interesting, the file you changed is no longer used by default since the --bazel_patch_module_resolver flag defaults to False. That means we should probably document how users should use --require source-map-support instead to get stack traces pointing back to original sources. (Or possibly do it for them in the launcher.sh, since we vendored the source-map-support package and always have it available)

@joeljeske do you have any time for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants