From ba0a01e7aabbb1622c682921519acec82cf74287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Fri, 4 Jul 2025 08:29:47 -0500 Subject: [PATCH] fix(eval): avoid stat calls in builtins.readDir Use entry.file_type() instead of entry.metadata().file_type() to avoid unnecessary stat syscalls. The file_type() method uses the cached d_type field from the readdir() syscall when available, eliminating the need for additional filesystem access. This matches the behavior described in https://github.com/NixOS/nix/pull/13412 where readDir should only read directory entries without stat'ing each file. Change-Id: I8983f84a7cff28b2c892d5829b9880ed22be4389 Reviewed-on: https://cl.snix.dev/c/snix/+/30596 Reviewed-by: Florian Klink Tested-by: besadii --- snix/eval/src/io.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/snix/eval/src/io.rs b/snix/eval/src/io.rs index 5a3e565e4..cf1558fd6 100644 --- a/snix/eval/src/io.rs +++ b/snix/eval/src/io.rs @@ -152,7 +152,10 @@ impl EvalIO for StdIO { for entry in path.read_dir()? { let entry = entry?; - let file_type = entry.metadata()?.file_type(); + // Use entry.file_type() instead of entry.metadata() to avoid stat syscalls. + // file_type() uses the d_type field from the readdir() syscall (when available), + // which is cached in the DirEntry and doesn't require additional filesystem access. + let file_type = entry.file_type()?; let val = if file_type.is_dir() { FileType::Directory