-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys: Use readdir withFileTypes option to skip lots of stat syscalls #35286
Conversation
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#22020 https://nodejs.org/en/blog/release/v10.10.0/ Signed-off-by: Anders Kaseorg <andersk@mit.edu>
96a40c3
to
bee7ee0
Compare
There was a problem hiding this comment.
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.
@@ -1413,8 +1424,7 @@ namespace 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(); |
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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.
2b983fa
to
01aec72
Compare
My reasoning was that the |
@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! |
The CI failure is unrelated. We're working on it. |
Closing and re-opening to re-trigger CI. |
01aec72
to
bee7ee0
Compare
Thanks, @andersk! My local benchmarking suggests this will make a big difference. And sorry about the delay in getting eyes on your PR. |
…icrosoft#35286) 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#22020 https://nodejs.org/en/blog/release/v10.10.0/ Signed-off-by: Anders Kaseorg <andersk@mit.edu>
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#22020
https://nodejs.org/en/blog/release/v10.10.0/