Skip to content

Commit 23c77c4

Browse files
authored
Merge pull request #40444 from amcasey/Cherry40043
Set stackTraceLimit to 0 in fileSystemEntryExists
2 parents 65b84e7 + 657576a commit 23c77c4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/compiler/sys.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,11 @@ namespace ts {
16621662
}
16631663

16641664
function fileSystemEntryExists(path: string, entryKind: FileSystemEntryKind): boolean {
1665+
// Since the error thrown by fs.statSync isn't used, we can avoid collecting a stack trace to improve
1666+
// the CPU time performance.
1667+
const originalStackTraceLimit = Error.stackTraceLimit;
1668+
Error.stackTraceLimit = 0;
1669+
16651670
try {
16661671
const stat = _fs.statSync(path);
16671672
switch (entryKind) {
@@ -1673,6 +1678,9 @@ namespace ts {
16731678
catch (e) {
16741679
return false;
16751680
}
1681+
finally {
1682+
Error.stackTraceLimit = originalStackTraceLimit;
1683+
}
16761684
}
16771685

16781686
function fileExists(path: string): boolean {

0 commit comments

Comments
 (0)