Skip to content
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

Counting entries in a directory #296

Closed
josephrocca opened this issue May 5, 2021 · 2 comments
Closed

Counting entries in a directory #296

josephrocca opened this issue May 5, 2021 · 2 comments

Comments

@josephrocca
Copy link

Does this API allow for a faster way of counting files in a directory than the example below?

const dirHandle = await window.showDirectoryPicker();
let count = 0;
for await (const entry of dirHandle.keys()) {
  count++;
}

I've been playing around with the API building a bulk file transformer/converter (demo/code) and the above method seems to be a bit slow when there are tens of thousands of files in the directory.

If operating system do track/cache this info then it would be great if it could be exposed in this API.

@slaymaker1907
Copy link

Is there anything about the interface that is inherently slow? Also please state which filesystem you tested this on. Windows in particular has weird performance characteristics for its filesystem.

I suspect the perf problem might be because of the excessive number of promises. In my opinion, .keys() should just return an array. If a directory has so many entries that this is bad for perf, the number of promises is also likely to cause perf problems and there should be a separate API which is something like AsyncIterator<Handle[]> so that way the event loop is handling say 50 entries at a time instead of a separate loop iteration and promise per handle. According to the JS spec, new Promise(cb) can't just run cb immediately and is effectively like setTimeout(cb, 0).

@mkruisselbrink
Copy link
Contributor

I think this is a duplicate of #215

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants