Skip to content

sys: Use readdir withFileTypes option to skip lots of stat syscalls - #35286

Merged
Andrew Casey (amcasey) merged 1 commit into
microsoft:masterfrom
andersk:readdir-withFileTypes
Jan 15, 2020
Merged

sys: Use readdir withFileTypes option to skip lots of stat syscalls#35286
Andrew Casey (amcasey) merged 1 commit into
microsoft:masterfrom
andersk:readdir-withFileTypes

Conversation

@andersk

@anderskAnders Kaseorg (andersk) commented Nov 22, 2019

Copy link
Copy Markdown
Contributor

@msftclas

Microsoft Contribution License Agreements (msftclas) commented Nov 22, 2019

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

This makes walking large directory trees much more efficient on Node
10.10 or later.
See:
https://lwn.net/Articles/606995/https://www.python.org/dev/peps/pep-0471/nodejs/node#22020https://nodejs.org/en/blog/release/v10.10.0/
Signed-off-by: Anders Kaseorg <andersk@mit.edu>

@amcaseyAndrew Casey (amcasey) left a comment

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.

Love it. Only suggestion is that we might want to do a single check up front, rather than looking for strings in every result. See #36139.

Comment threadsrc/compiler/sys.ts
function getDirectories(path: string): string[] {
perfLogger.logEvent("ReadDir: " + path);
return filter<string>(_fs.readdirSync(path), dir => fileSystemEntryExists(combinePaths(path, dir), FileSystemEntryKind.Directory));
return getAccessibleFileSystemEntries(path).directories.slice();

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.

You don't need to slice since getAccessibleFileSystemEntries returns new array for directories..

@anderskAnders Kaseorg (andersk)Jan 13, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Not always: return emptyFileSystemEntries does not. Of course, that’s easy to change. I’ve added a commit doing so.

Edit: I’ve now removed that commit again because we didn’t want to change the type of getAccessibleFileSystemEntries (at least not in this PR); see this discussion.

Comment threadsrc/compiler/sys.ts
@andersk
Anders Kaseorg (andersk)force-pushed the readdir-withFileTypes branch 2 times, most recently from 2b983fa to 01aec72CompareJanuary 13, 2020 20:31
@andersk

Copy link
Copy Markdown
ContributorAuthor

Only suggestion is that we might want to do a single check up front, rather than looking for strings in every result.

My reasoning was that the typeof checks are extremely cheap compared to the IO we’re doing (even now), and doing the check up front requires duplicating code. Let me know if you’d like me to do this anyway.

@amcasey

Copy link
Copy Markdown
Member

Anders Kaseorg (@andersk) I don't feel strongly either way. I agree that it's a small overhead, I just thought it seemed like a shame to pay it for all future versions (whereas an explicit version check is more likely to be cleaned up if we decide to deprecate older nodes). Either way, this is a huge improvement over the current implementation. Thanks again!

@amcasey

Copy link
Copy Markdown
Member

The CI failure is unrelated. We're working on it.

Comment threadsrc/compiler/sys.ts Outdated
@amcasey

Copy link
Copy Markdown
Member

Closing and re-opening to re-trigger CI.

@amcasey
Andrew Casey (amcasey) merged commit 64704a1 into microsoft:masterJan 15, 2020
@amcasey

Copy link
Copy Markdown
Member

Thanks, Anders Kaseorg (@andersk)! My local benchmarking suggests this will make a big difference. And sorry about the delay in getting eyes on your PR.

Wenlu Wang (Kingwl) pushed a commit to Kingwl/TypeScript that referenced this pull request Mar 4, 2020
@andersk
Anders Kaseorg (andersk) deleted the readdir-withFileTypes branch October 15, 2022 22:22
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@andersk@msftclas@amcasey@sheetalkamat