Skip to content

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

Closed
Wesley Wigham (weswigham) wants to merge 1 commit into
microsoft:masterfrom
weswigham:more-sys-error-stack-reductions
Closed

Wrap all imported fs methods to set error stack trace limit to zero during their execution#40125
Wesley Wigham (weswigham) wants to merge 1 commit into
microsoft:masterfrom
weswigham:more-sys-error-stack-reductions

Conversation

@weswigham

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 19, 2020

Copy link
Copy Markdown
Contributor

Heya Wesley Wigham (@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

TypeScript Bot (typescript-bot) commented Aug 19, 2020

Copy link
Copy Markdown
Contributor

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 19, 2020

Copy link
Copy Markdown
Contributor

Hey Wesley Wigham (@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.

Comment threadsrc/compiler/sys.ts
const result = {} as any;
for (const key in mod) {
if (!(mod[key] instanceof Function)) continue;
result[key] = (...args: any[]) => {

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
Copy Markdown
Contributor

Wesley Wigham (@weswigham)
The results of the perf run you requested are in!

Here they are:

Comparison Report - master..40125

Metricmaster40125DeltaBestWorst
Angular - node (v10.16.3, x64)
Memory used343,573k (± 0.02%)343,206k (± 0.01%)-368k (- 0.11%)343,068k343,297k
Parse Time2.00s (± 0.47%)2.01s (± 0.61%)+0.01s (+ 0.70%)1.99s2.04s
Bind Time0.82s (± 0.86%)0.82s (± 0.89%)+0.00s (+ 0.37%)0.81s0.84s
Check Time4.77s (± 0.90%)4.79s (± 0.64%)+0.02s (+ 0.50%)4.73s4.86s
Emit Time5.17s (± 0.59%)5.18s (± 0.65%)+0.01s (+ 0.14%)5.09s5.26s
Total Time12.76s (± 0.44%)12.80s (± 0.49%)+0.04s (+ 0.35%)12.63s12.97s
Monaco - node (v10.16.3, x64)
Memory used339,334k (± 0.03%)339,349k (± 0.05%)+15k (+ 0.00%)339,031k339,713k
Parse Time1.55s (± 0.64%)1.56s (± 0.57%)+0.01s (+ 0.71%)1.55s1.59s
Bind Time0.71s (± 0.87%)0.71s (± 0.81%)-0.00s (- 0.14%)0.70s0.72s
Check Time4.95s (± 0.75%)4.93s (± 0.36%)-0.02s (- 0.42%)4.90s4.98s
Emit Time2.74s (± 0.63%)2.74s (± 0.59%)0.00s ( 0.00%)2.70s2.79s
Total Time9.96s (± 0.47%)9.94s (± 0.27%)-0.01s (- 0.13%)9.91s10.04s
TFS - node (v10.16.3, x64)
Memory used302,166k (± 0.09%)302,229k (± 0.09%)+63k (+ 0.02%)301,958k303,252k
Parse Time1.21s (± 0.51%)1.22s (± 0.60%)+0.01s (+ 0.58%)1.20s1.23s
Bind Time0.67s (± 0.83%)0.67s (± 1.26%)+0.00s (+ 0.45%)0.65s0.68s
Check Time4.46s (± 0.78%)4.48s (± 0.55%)+0.02s (+ 0.49%)4.42s4.54s
Emit Time2.88s (± 1.52%)2.90s (± 1.14%)+0.01s (+ 0.45%)2.78s2.94s
Total Time9.22s (± 0.67%)9.27s (± 0.34%)+0.04s (+ 0.48%)9.20s9.33s
material-ui - node (v10.16.3, x64)
Memory used460,485k (± 0.02%)460,198k (± 0.01%)-287k (- 0.06%)460,047k460,295k
Parse Time1.96s (± 0.54%)1.96s (± 0.35%)+0.00s (+ 0.20%)1.95s1.98s
Bind Time0.65s (± 1.35%)0.66s (± 1.13%)+0.01s (+ 1.53%)0.65s0.68s
Check Time13.35s (± 0.69%)13.39s (± 0.53%)+0.04s (+ 0.28%)13.25s13.56s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.96s (± 0.61%)16.01s (± 0.46%)+0.05s (+ 0.32%)15.85s16.20s
Angular - node (v12.1.0, x64)
Memory used320,899k (± 0.02%)320,434k (± 0.02%)-465k (- 0.14%)320,292k320,626k
Parse Time1.99s (± 0.87%)2.00s (± 0.41%)+0.01s (+ 0.25%)1.98s2.01s
Bind Time0.80s (± 0.59%)0.81s (± 0.84%)+0.00s (+ 0.37%)0.79s0.82s
Check Time4.65s (± 0.51%)4.67s (± 0.59%)+0.02s (+ 0.47%)4.62s4.74s
Emit Time5.33s (± 0.35%)5.39s (± 0.71%)+0.06s (+ 1.07%)5.30s5.50s
Total Time12.78s (± 0.39%)12.87s (± 0.43%)+0.08s (+ 0.66%)12.73s12.97s
Monaco - node (v12.1.0, x64)
Memory used321,617k (± 0.02%)321,651k (± 0.02%)+33k (+ 0.01%)321,492k321,715k
Parse Time1.53s (± 0.84%)1.54s (± 0.52%)+0.01s (+ 0.52%)1.53s1.56s
Bind Time0.69s (± 0.68%)0.69s (± 0.68%)+0.00s (+ 0.00%)0.68s0.70s
Check Time4.73s (± 0.33%)4.74s (± 0.56%)+0.00s (+ 0.04%)4.70s4.82s
Emit Time2.79s (± 0.45%)2.81s (± 0.75%)+0.02s (+ 0.64%)2.76s2.87s
Total Time9.75s (± 0.26%)9.78s (± 0.34%)+0.03s (+ 0.29%)9.70s9.85s
TFS - node (v12.1.0, x64)
Memory used286,583k (± 0.03%)286,610k (± 0.03%)+27k (+ 0.01%)286,438k286,784k
Parse Time1.23s (± 0.48%)1.24s (± 0.67%)+0.01s (+ 0.82%)1.21s1.25s
Bind Time0.64s (± 0.97%)0.64s (± 0.76%)+0.01s (+ 0.78%)0.63s0.65s
Check Time4.35s (± 0.46%)4.35s (± 0.61%)-0.00s (- 0.05%)4.30s4.44s
Emit Time2.91s (± 0.73%)2.92s (± 1.22%)+0.01s (+ 0.38%)2.87s3.03s
Total Time9.13s (± 0.30%)9.15s (± 0.59%)+0.03s (+ 0.27%)9.08s9.35s
material-ui - node (v12.1.0, x64)
Memory used438,503k (± 0.08%)438,582k (± 0.02%)+80k (+ 0.02%)438,420k438,760k
Parse Time1.98s (± 0.50%)1.98s (± 0.42%)+0.00s (+ 0.20%)1.96s2.00s
Bind Time0.63s (± 0.64%)0.64s (± 1.42%)+0.01s (+ 1.59%)0.62s0.66s
Check Time12.01s (± 0.98%)12.04s (± 0.89%)+0.03s (+ 0.27%)11.77s12.35s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time14.62s (± 0.84%)14.67s (± 0.74%)+0.05s (+ 0.32%)14.36s14.96s
Angular - node (v8.9.0, x64)
Memory used340,200k (± 0.01%)339,842k (± 0.01%)-358k (- 0.11%)339,773k339,944k
Parse Time2.54s (± 0.51%)2.53s (± 0.56%)-0.01s (- 0.39%)2.50s2.57s
Bind Time0.85s (± 1.03%)0.85s (± 0.80%)+0.00s (+ 0.59%)0.84s0.87s
Check Time5.38s (± 0.53%)5.41s (± 0.50%)+0.03s (+ 0.50%)5.36s5.47s
Emit Time5.88s (± 1.02%)5.91s (± 1.22%)+0.03s (+ 0.54%)5.76s6.07s
Total Time14.66s (± 0.55%)14.71s (± 0.57%)+0.06s (+ 0.38%)14.58s14.95s
Monaco - node (v8.9.0, x64)
Memory used340,522k (± 0.01%)340,571k (± 0.01%)+49k (+ 0.01%)340,453k340,691k
Parse Time1.87s (± 0.40%)1.88s (± 0.69%)+0.01s (+ 0.37%)1.86s1.92s
Bind Time0.88s (± 0.41%)0.89s (± 0.67%)+0.00s (+ 0.23%)0.88s0.90s
Check Time5.45s (± 0.70%)5.47s (± 0.62%)+0.02s (+ 0.44%)5.39s5.53s
Emit Time3.22s (± 0.41%)3.24s (± 0.91%)+0.02s (+ 0.56%)3.20s3.32s
Total Time11.43s (± 0.47%)11.48s (± 0.54%)+0.05s (+ 0.44%)11.35s11.65s
TFS - node (v8.9.0, x64)
Memory used303,877k (± 0.02%)303,887k (± 0.01%)+10k (+ 0.00%)303,841k303,987k
Parse Time1.54s (± 0.53%)1.56s (± 0.89%)+0.02s (+ 1.04%)1.53s1.59s
Bind Time0.67s (± 1.01%)0.67s (± 0.55%)+0.00s (+ 0.15%)0.67s0.68s
Check Time5.18s (± 0.35%)5.24s (± 0.52%)+0.05s (+ 1.06%)5.18s5.29s
Emit Time2.93s (± 0.71%)2.94s (± 1.20%)+0.01s (+ 0.38%)2.82s3.00s
Total Time10.32s (± 0.29%)10.41s (± 0.61%)+0.09s (+ 0.87%)10.24s10.52s
material-ui - node (v8.9.0, x64)
Memory used464,815k (± 0.01%)464,575k (± 0.01%)-240k (- 0.05%)464,394k464,678k
Parse Time2.40s (± 0.37%)2.41s (± 0.45%)+0.01s (+ 0.38%)2.39s2.44s
Bind Time0.78s (± 0.97%)0.79s (± 1.19%)+0.01s (+ 0.64%)0.76s0.80s
Check Time18.07s (± 0.73%)17.94s (± 0.99%)-0.12s (- 0.68%)17.45s18.35s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time21.25s (± 0.63%)21.14s (± 0.85%)-0.11s (- 0.49%)20.63s21.54s
Angular - node (v8.9.0, x86)
Memory used195,211k (± 0.03%)195,078k (± 0.01%)-133k (- 0.07%)195,036k195,124k
Parse Time2.48s (± 1.13%)2.48s (± 0.52%)+0.00s (+ 0.08%)2.46s2.52s
Bind Time0.99s (± 1.26%)0.99s (± 0.60%)+0.01s (+ 0.71%)0.98s1.01s
Check Time4.85s (± 0.45%)4.87s (± 0.57%)+0.02s (+ 0.41%)4.82s4.95s
Emit Time5.88s (± 1.44%)5.90s (± 1.48%)+0.01s (+ 0.19%)5.70s6.12s
Total Time14.21s (± 0.73%)14.24s (± 0.76%)+0.04s (+ 0.25%)14.06s14.54s
Monaco - node (v8.9.0, x86)
Memory used193,594k (± 0.02%)193,620k (± 0.02%)+26k (+ 0.01%)193,546k193,705k
Parse Time1.92s (± 1.22%)1.90s (± 0.31%)-0.02s (- 0.94%)1.89s1.92s
Bind Time0.70s (± 0.48%)0.70s (± 0.63%)-0.00s (- 0.14%)0.69s0.71s
Check Time5.56s (± 0.47%)5.57s (± 0.34%)+0.01s (+ 0.16%)5.54s5.62s
Emit Time2.67s (± 0.60%)2.68s (± 0.91%)+0.01s (+ 0.45%)2.63s2.74s
Total Time10.86s (± 0.30%)10.86s (± 0.27%)+0.00s (+ 0.02%)10.79s10.92s
TFS - node (v8.9.0, x86)
Memory used173,839k (± 0.02%)173,829k (± 0.02%)-9k (- 0.01%)173,711k173,912k
Parse Time1.58s (± 0.37%)1.59s (± 0.78%)+0.02s (+ 1.01%)1.57s1.62s
Bind Time0.64s (± 0.46%)0.64s (± 0.35%)-0.00s (- 0.16%)0.64s0.65s
Check Time4.70s (± 0.69%)4.71s (± 0.53%)+0.01s (+ 0.17%)4.66s4.77s
Emit Time2.80s (± 1.25%)2.83s (± 1.47%)+0.03s (+ 1.04%)2.78s2.93s
Total Time9.72s (± 0.52%)9.78s (± 0.39%)+0.06s (+ 0.58%)9.72s9.88s
material-ui - node (v8.9.0, x86)
Memory used263,197k (± 0.01%)263,097k (± 0.02%)-100k (- 0.04%)262,997k263,167k
Parse Time2.45s (± 0.97%)2.45s (± 0.52%)-0.00s (- 0.12%)2.43s2.48s
Bind Time0.67s (± 1.23%)0.71s (± 5.64%)+0.03s (+ 4.60%)0.66s0.86s
Check Time16.50s (± 0.47%)16.45s (± 0.59%)-0.05s (- 0.30%)16.20s16.70s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time19.62s (± 0.43%)19.61s (± 0.53%)-0.02s (- 0.08%)19.36s19.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)
BenchmarkNameIterations
Current4012510
Baselinemaster10

Comment threadsrc/compiler/sys.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
Copy Markdown
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
Copy Markdown
MemberAuthor

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
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

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
Copy Markdown
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.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: TeamFor Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants

@weswigham@typescript-bot@amcasey@RyanCavanaugh@DanielRosenwasser@sheetalkamat@sandersn