Skip to content

Wrap all imported fs methods to set error stack trace limit to zero during their execution #40125

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

Closed

Conversation

weswigham
Copy link
Member

This is just a followup to #40043 that blanket applies the idea to all fs methods we use (or will use in the future), rather than just one specific statSync usage.

@weswigham
Copy link
Member Author

@typescript-bot perf test this
@typescript-bot pack this

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Aug 19, 2020
@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 19, 2020

Heya @weswigham, I've started to run the perf test suite on this PR at 82dcd62. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 19, 2020

Heya @weswigham, I've started to run the tarball bundle task on this PR at 82dcd62. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 19, 2020

Hey @weswigham, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/82661/artifacts?artifactName=tgz&fileId=7E92E36CAD248D57CED4E1A0AB50BA7055042D5F6C89ECAF22C46A49FF09CEA402&fileName=/typescript-4.1.0-insiders.20200819.tgz"
    }
}

and then running npm install.


There is also a playground for this build.

const result = {} as any;
for (const key in mod) {
if (!(mod[key] instanceof Function)) continue;
result[key] = (...args: any[]) => {
Copy link
Member

Choose a reason for hiding this comment

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

Worth understanding whether an allocation for this array in each call is a potential problem.

@typescript-bot
Copy link
Collaborator

@weswigham
The results of the perf run you requested are in!

Here they are:

Comparison Report - master..40125

Metric master 40125 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 343,573k (± 0.02%) 343,206k (± 0.01%) -368k (- 0.11%) 343,068k 343,297k
Parse Time 2.00s (± 0.47%) 2.01s (± 0.61%) +0.01s (+ 0.70%) 1.99s 2.04s
Bind Time 0.82s (± 0.86%) 0.82s (± 0.89%) +0.00s (+ 0.37%) 0.81s 0.84s
Check Time 4.77s (± 0.90%) 4.79s (± 0.64%) +0.02s (+ 0.50%) 4.73s 4.86s
Emit Time 5.17s (± 0.59%) 5.18s (± 0.65%) +0.01s (+ 0.14%) 5.09s 5.26s
Total Time 12.76s (± 0.44%) 12.80s (± 0.49%) +0.04s (+ 0.35%) 12.63s 12.97s
Monaco - node (v10.16.3, x64)
Memory used 339,334k (± 0.03%) 339,349k (± 0.05%) +15k (+ 0.00%) 339,031k 339,713k
Parse Time 1.55s (± 0.64%) 1.56s (± 0.57%) +0.01s (+ 0.71%) 1.55s 1.59s
Bind Time 0.71s (± 0.87%) 0.71s (± 0.81%) -0.00s (- 0.14%) 0.70s 0.72s
Check Time 4.95s (± 0.75%) 4.93s (± 0.36%) -0.02s (- 0.42%) 4.90s 4.98s
Emit Time 2.74s (± 0.63%) 2.74s (± 0.59%) 0.00s ( 0.00%) 2.70s 2.79s
Total Time 9.96s (± 0.47%) 9.94s (± 0.27%) -0.01s (- 0.13%) 9.91s 10.04s
TFS - node (v10.16.3, x64)
Memory used 302,166k (± 0.09%) 302,229k (± 0.09%) +63k (+ 0.02%) 301,958k 303,252k
Parse Time 1.21s (± 0.51%) 1.22s (± 0.60%) +0.01s (+ 0.58%) 1.20s 1.23s
Bind Time 0.67s (± 0.83%) 0.67s (± 1.26%) +0.00s (+ 0.45%) 0.65s 0.68s
Check Time 4.46s (± 0.78%) 4.48s (± 0.55%) +0.02s (+ 0.49%) 4.42s 4.54s
Emit Time 2.88s (± 1.52%) 2.90s (± 1.14%) +0.01s (+ 0.45%) 2.78s 2.94s
Total Time 9.22s (± 0.67%) 9.27s (± 0.34%) +0.04s (+ 0.48%) 9.20s 9.33s
material-ui - node (v10.16.3, x64)
Memory used 460,485k (± 0.02%) 460,198k (± 0.01%) -287k (- 0.06%) 460,047k 460,295k
Parse Time 1.96s (± 0.54%) 1.96s (± 0.35%) +0.00s (+ 0.20%) 1.95s 1.98s
Bind Time 0.65s (± 1.35%) 0.66s (± 1.13%) +0.01s (+ 1.53%) 0.65s 0.68s
Check Time 13.35s (± 0.69%) 13.39s (± 0.53%) +0.04s (+ 0.28%) 13.25s 13.56s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.96s (± 0.61%) 16.01s (± 0.46%) +0.05s (+ 0.32%) 15.85s 16.20s
Angular - node (v12.1.0, x64)
Memory used 320,899k (± 0.02%) 320,434k (± 0.02%) -465k (- 0.14%) 320,292k 320,626k
Parse Time 1.99s (± 0.87%) 2.00s (± 0.41%) +0.01s (+ 0.25%) 1.98s 2.01s
Bind Time 0.80s (± 0.59%) 0.81s (± 0.84%) +0.00s (+ 0.37%) 0.79s 0.82s
Check Time 4.65s (± 0.51%) 4.67s (± 0.59%) +0.02s (+ 0.47%) 4.62s 4.74s
Emit Time 5.33s (± 0.35%) 5.39s (± 0.71%) +0.06s (+ 1.07%) 5.30s 5.50s
Total Time 12.78s (± 0.39%) 12.87s (± 0.43%) +0.08s (+ 0.66%) 12.73s 12.97s
Monaco - node (v12.1.0, x64)
Memory used 321,617k (± 0.02%) 321,651k (± 0.02%) +33k (+ 0.01%) 321,492k 321,715k
Parse Time 1.53s (± 0.84%) 1.54s (± 0.52%) +0.01s (+ 0.52%) 1.53s 1.56s
Bind Time 0.69s (± 0.68%) 0.69s (± 0.68%) +0.00s (+ 0.00%) 0.68s 0.70s
Check Time 4.73s (± 0.33%) 4.74s (± 0.56%) +0.00s (+ 0.04%) 4.70s 4.82s
Emit Time 2.79s (± 0.45%) 2.81s (± 0.75%) +0.02s (+ 0.64%) 2.76s 2.87s
Total Time 9.75s (± 0.26%) 9.78s (± 0.34%) +0.03s (+ 0.29%) 9.70s 9.85s
TFS - node (v12.1.0, x64)
Memory used 286,583k (± 0.03%) 286,610k (± 0.03%) +27k (+ 0.01%) 286,438k 286,784k
Parse Time 1.23s (± 0.48%) 1.24s (± 0.67%) +0.01s (+ 0.82%) 1.21s 1.25s
Bind Time 0.64s (± 0.97%) 0.64s (± 0.76%) +0.01s (+ 0.78%) 0.63s 0.65s
Check Time 4.35s (± 0.46%) 4.35s (± 0.61%) -0.00s (- 0.05%) 4.30s 4.44s
Emit Time 2.91s (± 0.73%) 2.92s (± 1.22%) +0.01s (+ 0.38%) 2.87s 3.03s
Total Time 9.13s (± 0.30%) 9.15s (± 0.59%) +0.03s (+ 0.27%) 9.08s 9.35s
material-ui - node (v12.1.0, x64)
Memory used 438,503k (± 0.08%) 438,582k (± 0.02%) +80k (+ 0.02%) 438,420k 438,760k
Parse Time 1.98s (± 0.50%) 1.98s (± 0.42%) +0.00s (+ 0.20%) 1.96s 2.00s
Bind Time 0.63s (± 0.64%) 0.64s (± 1.42%) +0.01s (+ 1.59%) 0.62s 0.66s
Check Time 12.01s (± 0.98%) 12.04s (± 0.89%) +0.03s (+ 0.27%) 11.77s 12.35s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 14.62s (± 0.84%) 14.67s (± 0.74%) +0.05s (+ 0.32%) 14.36s 14.96s
Angular - node (v8.9.0, x64)
Memory used 340,200k (± 0.01%) 339,842k (± 0.01%) -358k (- 0.11%) 339,773k 339,944k
Parse Time 2.54s (± 0.51%) 2.53s (± 0.56%) -0.01s (- 0.39%) 2.50s 2.57s
Bind Time 0.85s (± 1.03%) 0.85s (± 0.80%) +0.00s (+ 0.59%) 0.84s 0.87s
Check Time 5.38s (± 0.53%) 5.41s (± 0.50%) +0.03s (+ 0.50%) 5.36s 5.47s
Emit Time 5.88s (± 1.02%) 5.91s (± 1.22%) +0.03s (+ 0.54%) 5.76s 6.07s
Total Time 14.66s (± 0.55%) 14.71s (± 0.57%) +0.06s (+ 0.38%) 14.58s 14.95s
Monaco - node (v8.9.0, x64)
Memory used 340,522k (± 0.01%) 340,571k (± 0.01%) +49k (+ 0.01%) 340,453k 340,691k
Parse Time 1.87s (± 0.40%) 1.88s (± 0.69%) +0.01s (+ 0.37%) 1.86s 1.92s
Bind Time 0.88s (± 0.41%) 0.89s (± 0.67%) +0.00s (+ 0.23%) 0.88s 0.90s
Check Time 5.45s (± 0.70%) 5.47s (± 0.62%) +0.02s (+ 0.44%) 5.39s 5.53s
Emit Time 3.22s (± 0.41%) 3.24s (± 0.91%) +0.02s (+ 0.56%) 3.20s 3.32s
Total Time 11.43s (± 0.47%) 11.48s (± 0.54%) +0.05s (+ 0.44%) 11.35s 11.65s
TFS - node (v8.9.0, x64)
Memory used 303,877k (± 0.02%) 303,887k (± 0.01%) +10k (+ 0.00%) 303,841k 303,987k
Parse Time 1.54s (± 0.53%) 1.56s (± 0.89%) +0.02s (+ 1.04%) 1.53s 1.59s
Bind Time 0.67s (± 1.01%) 0.67s (± 0.55%) +0.00s (+ 0.15%) 0.67s 0.68s
Check Time 5.18s (± 0.35%) 5.24s (± 0.52%) +0.05s (+ 1.06%) 5.18s 5.29s
Emit Time 2.93s (± 0.71%) 2.94s (± 1.20%) +0.01s (+ 0.38%) 2.82s 3.00s
Total Time 10.32s (± 0.29%) 10.41s (± 0.61%) +0.09s (+ 0.87%) 10.24s 10.52s
material-ui - node (v8.9.0, x64)
Memory used 464,815k (± 0.01%) 464,575k (± 0.01%) -240k (- 0.05%) 464,394k 464,678k
Parse Time 2.40s (± 0.37%) 2.41s (± 0.45%) +0.01s (+ 0.38%) 2.39s 2.44s
Bind Time 0.78s (± 0.97%) 0.79s (± 1.19%) +0.01s (+ 0.64%) 0.76s 0.80s
Check Time 18.07s (± 0.73%) 17.94s (± 0.99%) -0.12s (- 0.68%) 17.45s 18.35s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 21.25s (± 0.63%) 21.14s (± 0.85%) -0.11s (- 0.49%) 20.63s 21.54s
Angular - node (v8.9.0, x86)
Memory used 195,211k (± 0.03%) 195,078k (± 0.01%) -133k (- 0.07%) 195,036k 195,124k
Parse Time 2.48s (± 1.13%) 2.48s (± 0.52%) +0.00s (+ 0.08%) 2.46s 2.52s
Bind Time 0.99s (± 1.26%) 0.99s (± 0.60%) +0.01s (+ 0.71%) 0.98s 1.01s
Check Time 4.85s (± 0.45%) 4.87s (± 0.57%) +0.02s (+ 0.41%) 4.82s 4.95s
Emit Time 5.88s (± 1.44%) 5.90s (± 1.48%) +0.01s (+ 0.19%) 5.70s 6.12s
Total Time 14.21s (± 0.73%) 14.24s (± 0.76%) +0.04s (+ 0.25%) 14.06s 14.54s
Monaco - node (v8.9.0, x86)
Memory used 193,594k (± 0.02%) 193,620k (± 0.02%) +26k (+ 0.01%) 193,546k 193,705k
Parse Time 1.92s (± 1.22%) 1.90s (± 0.31%) -0.02s (- 0.94%) 1.89s 1.92s
Bind Time 0.70s (± 0.48%) 0.70s (± 0.63%) -0.00s (- 0.14%) 0.69s 0.71s
Check Time 5.56s (± 0.47%) 5.57s (± 0.34%) +0.01s (+ 0.16%) 5.54s 5.62s
Emit Time 2.67s (± 0.60%) 2.68s (± 0.91%) +0.01s (+ 0.45%) 2.63s 2.74s
Total Time 10.86s (± 0.30%) 10.86s (± 0.27%) +0.00s (+ 0.02%) 10.79s 10.92s
TFS - node (v8.9.0, x86)
Memory used 173,839k (± 0.02%) 173,829k (± 0.02%) -9k (- 0.01%) 173,711k 173,912k
Parse Time 1.58s (± 0.37%) 1.59s (± 0.78%) +0.02s (+ 1.01%) 1.57s 1.62s
Bind Time 0.64s (± 0.46%) 0.64s (± 0.35%) -0.00s (- 0.16%) 0.64s 0.65s
Check Time 4.70s (± 0.69%) 4.71s (± 0.53%) +0.01s (+ 0.17%) 4.66s 4.77s
Emit Time 2.80s (± 1.25%) 2.83s (± 1.47%) +0.03s (+ 1.04%) 2.78s 2.93s
Total Time 9.72s (± 0.52%) 9.78s (± 0.39%) +0.06s (+ 0.58%) 9.72s 9.88s
material-ui - node (v8.9.0, x86)
Memory used 263,197k (± 0.01%) 263,097k (± 0.02%) -100k (- 0.04%) 262,997k 263,167k
Parse Time 2.45s (± 0.97%) 2.45s (± 0.52%) -0.00s (- 0.12%) 2.43s 2.48s
Bind Time 0.67s (± 1.23%) 0.71s (± 5.64%) +0.03s (+ 4.60%) 0.66s 0.86s
Check Time 16.50s (± 0.47%) 16.45s (± 0.59%) -0.05s (- 0.30%) 16.20s 16.70s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 19.62s (± 0.43%) 19.61s (± 0.53%) -0.02s (- 0.08%) 19.36s 19.82s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-166-generic
Architecturex64
Available Memory16 GB
Available Memory1 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v8.9.0, x64)
  • node (v8.9.0, x86)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v8.9.0, x64)
  • Angular - node (v8.9.0, x86)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v8.9.0, x64)
  • Monaco - node (v8.9.0, x86)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v8.9.0, x64)
  • TFS - node (v8.9.0, x86)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v8.9.0, x64)
  • material-ui - node (v8.9.0, x86)
Benchmark Name Iterations
Current 40125 10
Baseline master 10

@@ -1135,7 +1155,7 @@ namespace ts {

function getNodeSystem(): System {
const nativePattern = /^native |^\([^)]+\)$|^(internal[\\/]|[a-zA-Z0-9_\s]+(\.js)?$)/;
const _fs: typeof import("fs") = require("fs");
const _fs: typeof import("fs") = wrapStacktraceReduction(require("fs"));
Copy link
Member

Choose a reason for hiding this comment

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

if we are doing this in sys for all functions, we should do it for all the other uses of fs too.. (nodeTypingInstaller, server etc)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, fair enough, I just didn't realize other things used fs directly rather than sys.

@amcasey
Copy link
Member

amcasey commented Aug 20, 2020

Is it really the case that we never want a stack from fs? I was only thinking of applying this to statSync calls. Do you have an example of what a stack will look like if, e.g. a file we're trying to write to is locked?

@weswigham
Copy link
Member Author

We never inspect the .stack property of an error thrown by these calls, and always catch them (and either always do one thing or inspect the error code and change the action depending on it) - so programatically, no, we never care about the stack from these.

@RyanCavanaugh
Copy link
Member

This doesn't seem like a great win for perf overall. We're introducing this overhead on every fs call, even though there's only a small number that regularly throw, and also introducing a duplicative try block for the cases that do have a wrapping try/catch. I'd want to see more concrete evidence that this is an overall perf win before introducing this complexity.

@sandersn sandersn assigned sheetalkamat and unassigned weswigham Sep 8, 2020
@weswigham weswigham closed this Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants