展示HN:Rmbrr – Rust中的并行目录删除工具
我厌倦了等待删除 node_modules,所以我开发了 rmbrr。在我的电脑上,它比 rimraf 在 Windows 上快 44%(1.8 秒对比 3.2 秒),在 WSL 上快 61%(192 毫秒对比 660 毫秒)。
方法:单次递归扫描构建依赖图,然后并行工作者自底向上删除。一旦某个目录的最后一个子项完成,它会自动排队等待删除。
在 Windows 上,我使用 POSIX 删除语义(通过 SetFileInformationByHandle 的 FILE_DISPOSITION_POSIX_SEMANTICS),这可以实现即时的命名空间移除,并且能够处理只读或正在使用的文件,而无需重试循环。
在 Unix 上,使用标准系统调用的相同并行架构。
该工具使用 Rust 编写,以本地二进制形式发布,并提供可选的 npm/brew/cargo 以便于安装。
GitHub: [https://github.com/mtopolski/rmbrr](https://github.com/mtopolski/rmbrr)
npm: [https://www.npmjs.com/package/rmbrr](https://www.npmjs.com/package/rmbrr)
基准测试详情请见 README - 已在 28K+ 文件的 node_modules 目录上进行测试。
查看原文
I got tired of waiting for node_modules to delete, so I built rmbrr. On my box it takes 44% less time than rimraf on Windows (1.8s vs 3.2s) and 61% less time on WSL (192ms vs 660ms).<p>The approach: single-pass recursive scan builds a dependency graph, then parallel workers delete bottom-up. As soon as a directory's last child completes, it's automatically queued for deletion.<p>On Windows, I use POSIX delete semantics (FILE_DISPOSITION_POSIX_SEMANTICS via SetFileInformationByHandle) which gives immediate namespace removal and handles read-only/in-use files without retry loops.<p>On Unix, same parallel architecture using standard syscalls.<p>Written in Rust, ships as a native binary with optional npm/brew/cargo for easy installation.<p>GitHub: <a href="https://github.com/mtopolski/rmbrr" rel="nofollow">https://github.com/mtopolski/rmbrr</a>
npm: <a href="https://www.npmjs.com/package/rmbrr" rel="nofollow">https://www.npmjs.com/package/rmbrr</a><p>Benchmark details in README - tested on 28K+ file node_modules directories.