deno icon indicating copy to clipboard operation
deno copied to clipboard

perf(node/fs): speedup fs.readdir + async

Open marvinhagemeister opened this issue 1 year ago • 2 comments
trafficstars

Whilst working on Node compat issues I noticed that we could make the family of readdir* functions a lot faster

  • Avoid shape transition when withFileTypes option is used
  • Add fast path for usages without withFileTypes to skip allocations on both the JS and Rust side
  • Call ops directly instead of layering on top of Deno.* JS APIs.
Benchmark main (iter/s) PR (iter/s)
fs.readdir 1,141.0 2,287.8
fs.readdirSync 1,434.9 2,406.8
fs.readdir + withFileTypes 1,101.0 1,407.2
fs.readdirSync + withFileTypes 1,372.8 1,481.9

marvinhagemeister avatar Jul 10 '24 22:07 marvinhagemeister

I've removed the old dirent tests because they were constructing Dirent instances directly which is disallowed in node types. Instead, I've ported those tests to two actual readdir ones that assert based on the actual result.

marvinhagemeister avatar Jul 11 '24 07:07 marvinhagemeister

@marvinhagemeister is this something we can land?

bartlomieju avatar Oct 26 '24 22:10 bartlomieju

closing because old

ry avatar May 08 '25 23:05 ry