Skip to content

Commit

Permalink
Stacktrace optimization for getModified time in anticipation of using…
Browse files Browse the repository at this point in the history
… it more than fileExists wherever possible
  • Loading branch information
sheetalkamat committed Apr 19, 2022
1 parent 87a7112 commit 16cef4a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1859,12 +1859,19 @@ namespace ts {
}

function getModifiedTime(path: string) {
// Since the error thrown by fs.statSync isn't used, we can avoid collecting a stack trace to improve
// the CPU time performance.
const originalStackTraceLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 0;
try {
return statSync(path)?.mtime;
}
catch (e) {
return undefined;
}
finally {
Error.stackTraceLimit = originalStackTraceLimit;
}
}

function setModifiedTime(path: string, time: Date) {
Expand Down

0 comments on commit 16cef4a

Please sign in to comment.