Skip to content

Conversation

@amcasey
Copy link
Member

@amcasey amcasey commented Jan 11, 2020

While writing a benchmark, I happened to notice that (a) the natural
win32 APIs for this task include "isDirectory" in the result and (b)
readDirSync will return entries, rather than strings, if you pass
withFileTypes. It turns out this version, which allows us to dispense
with path math and stat calls is ~20X faster (enumerating a directory
with 600 children).

While writing a benchmark, I happened to notice that (a) the natural
win32 APIs for this task include "isDirectory" in the result and (b)
readDirSync will return entries, rather than strings, if you pass
withFileTypes.  It turns out this version, which allows us to dispense
with path math and stat calls is ~30X faster (enumerating a directory
with 600 children).
@minestarks
Copy link
Member

Struggling to find an emoji to express my joy

@amcasey
Copy link
Member Author

amcasey commented Jan 11, 2020

On Node 8 on Linux, the flag is ignored and strings are returned regardless.

@amcasey
Copy link
Member Author

amcasey commented Jan 11, 2020

Node 10 on Linux shows a ~5X improvement, so it's probably worth finding a way to special case Node 8 on Linux.

@amcasey amcasey requested a review from sheetalkamat January 11, 2020 03:46
@ajafff
Copy link
Contributor

ajafff commented Jan 11, 2020

There's already a PR to use withFileTypes which is waiting for review for a few weeks.

@amcasey
Copy link
Member Author

amcasey commented Jan 13, 2020

@ajafff Thanks for the link! Closing in favor of #35286.

@amcasey amcasey closed this Jan 13, 2020
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

Sign up for free to 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