Skip to content

Commit 16cef4a

Browse files
committed
Stacktrace optimization for getModified time in anticipation of using it more than fileExists wherever possible
1 parent 87a7112 commit 16cef4a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/compiler/sys.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1859,12 +1859,19 @@ namespace ts {
18591859
}
18601860

18611861
function getModifiedTime(path: string) {
1862+
// Since the error thrown by fs.statSync isn't used, we can avoid collecting a stack trace to improve
1863+
// the CPU time performance.
1864+
const originalStackTraceLimit = Error.stackTraceLimit;
1865+
Error.stackTraceLimit = 0;
18621866
try {
18631867
return statSync(path)?.mtime;
18641868
}
18651869
catch (e) {
18661870
return undefined;
18671871
}
1872+
finally {
1873+
Error.stackTraceLimit = originalStackTraceLimit;
1874+
}
18681875
}
18691876

18701877
function setModifiedTime(path: string, time: Date) {

0 commit comments

Comments
 (0)