fdf - High-Performance POSIX File Finder
fdf is a high-performance POSIX file finder written in Rust with extensive C FFI.
It serves as a lightweight alternative to tools such as fd and find, with a focus on speed, efficiency, and cross-platform compatibility. Benchmarks demonstrate fdf running up to 2x faster than comparable tools, achieved through low-level optimisation, SIMD techniques, and direct syscalls(where possible).
Note, my philosophy is to keep this non-publicised at at all until a 1.0.
PLEASE NOTE: This is due to undergo a rename before a 1.0, I am tending towards frep as a name
Windows version: Requires significant rewrite, planned for post 1.0.
Quick Installation:
## Additionally specify --no-default-features to remove mimalloc dependency
Project Status
This is a performance-focused project that remains under active development towards a stable 1.0 release. The current name is temporary and will change before that release.
The CLI is already usable, but the internal library API is not yet stable.
Platform Support
Fully Supported and CI Tested
- Linux (x86_64, s390x (Big endian), Alpine( MUSL libc))
- macOS (Intel and Apple Silicon)
- FreeBSD (x86_64)
- NetBSD (x86_64)
- OpenBSD (x86_64)
- Solaris/Illumos(x86_64)
Compiles with Limited Testing
Note: GitHub Actions does not yet provide Rust 2024 support for some of these platforms. Additional checks will be added when available.
- Android
- 32-bit Linux
Other POSIX operating systems, such as AIX, are currently untested.
Not Yet Supported
-
Windows: Requires significant rewrite due to architectural differences with libc. Planned once the POSIX feature set is stable.
-
DragonflyBSD: Blocked on Rust 2024 support.
Testing
The project includes comprehensive testing with 100+ Rust tests and 15+ correctness benchmarks comparing against fd.
Miri validation (Rust's undefined behaviour detector) is not practical here due to the extensive libc usage, so validation relies on intensive testing and Valgrind. See scripts/valgrind-test.sh.
- Rust tests: Available here
- Shell scripts clone the LLVM repository to provide an accurate testing environment
- Tests run via GitHub Actions on all supported platforms
Running the Full Test Suite:
TMP_DIR=""
This runs the internal library tests, CLI tests, and benchmarks.
Performance Benchmarks
The benchmarks are repeatable using the testing code above and cover file type filtering, extension matching, file sizes, and several other scenarios. The following results were gathered on Linux against local directories and the LLVM repository and summarised from hyperfine output.
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
--Average Speedup: 2.20x--
Distinctions from fd/find
Symlink resolution in my method differs from fd and find. Although I generally advise against following symlinks, the option exists for completeness.
When following symlinks, behaviour will vary slightly. For example, fd can enter infinite loops with recursive symlinks (see recursive_symlink_fs_test.sh) Available here whereas my implementation prevents hangs. It may, however, return more results than expected.
To avoid issues, use --same-file-system when traversing symlinks. This ensures traversal terminates safely even in complex directories such as ~/.steam, ~/.wine, /sys, and /proc.
Technical Highlights
Key Optimisations
-
getdents64/getdents: Optimised the Linux/Android-specific/OpenBSD/NetBSD/Illumos/Solaris directory reading by significantly reducing the number of stat/statx/fstatat system calls
-
Reverse engineered MacOS syscalls(
__getdirentries64) to exploit early EOF and no unnecessary stat/pthread_mutex calls at link here and this link for syscall implementation (Also works on FreeBSD) -
memrchr optimisation with 20%~ improvement on stdlib (SWAR optimisation)
-
An optimised gitignore parser with 5x fewer stat64/statx calls.
-
A custom written crossbeam workstealing parallel traversal algorithm
Constant-Time Directory Entry Processing
The following function provides an elegant solution to avoid branch mispredictions/SIMD instructions during directory entry parsing (a performance-critical loop):
Check source code for further explanation in utils.rs**
This version is simplified from the actual implementation
// Computational complexity: O(1) - truly constant time
// Used mostly on Linux type systems
// SIMD within a register, so no architecture dependence
//http://www.icodeguru.com/Embedded/Hacker%27s-Delight/043.htm
pub const unsafe
Why?
I started this project because I found find slow and wanted to learn how to interface directly with the kernel. What began as a small experiment became a practical tool for exploring low-level systems work.
Performance Motivation
Rust's std::fs has inefficiencies for this workload, including extra allocation, file descriptor handling overhead, repeated strlen work, and readdir-based traversal. Rewriting those paths with libc allowed tighter control over traversal costs and was a useful learning exercise.
The standard library can also keep file descriptors open until the last reference to an inner ReadDir disappears, which can become limiting on Unix systems with lower descriptor limits.
It also tends to rely heavily on stat-style calls, which is costly in traversal-heavy workloads.
See fd_benchmarks/syscalltest.sh for a rough syscall comparison.
Development Philosophy
Feature stability before breakage - I won't push breaking changes or advertise this anywhere until I've got a good baseline.
Open to contributions - Once the codebase stabilises, contributions are welcome.
In short, this project explores performance, low-level programming, and practical tooling.
Acknowledgements/Disclaimers
I've directly taken code from fnmatch-regex, found at the link and modified it so I could convert globs to regex patterns trivially, this simplifies the string filtering model by delegating it to rust's extremely fast regex crate. Notably I modified it because it's quite old and has dependencies I was able to remove
(I have emailed and received approval from the author above)
I've also done so for some SWAR tricks from the standard library (see link) which is implemented at the following link I additionally emailed the author of memchr and got some nice tips, great guy, someone I respect whole heartedly!
Future Plans
Feature Enhancements (Planned)
API cleanup, currently the CLI is the main focus but I'd like to fix that eventually!
POSIX Compliance: Mostly done, I don't expect to extend this beyond Linux/BSD/MacOS/Illumos/Solaris/Android (the other ones are embedded mostly, correct me if i'm wrong!), I have tentative work for other OS'es, it may support NuttX/few others but completely untested.
Ultimately, these are an extremely fringe usecase and I think it is beyond pointless to focus on these.
Platform Expansion
Windows Support: Acknowledged as a significant undertaking an almost entire separate codebase(portability ain't fun), but valuable for both usability and learning Windows internals.
Installation and Usage
# Clone & build
# Optional system install
# Find all JPG files in the home directory (excluding hidden files)
# Find all Python files in /usr/local (including hidden files)
# Null terminated all output instead of newlines, mainly for command passing to other functions
|
# Generate shell completions for Zsh/bash (also supports powershell/fish!)
# For Zsh
# For Bash
## Options
)
)
Potential Future Enhancements
1. io_uring System Call Batching
- Investigate batching of
statand similar operations. - Key challenges:
- No native
getdentssupport inio_uring. - Would require async runtime integration (e.g. Tokio).
- Conflicts with the project’s minimal-dependency design.
- Linux-only feature, making it a low-priority and high-effort addition. I will likely NOT do this
- No native
2. Allocation-Optimised Iterator Adaptor
- Implement a filtering mechanism that avoids unnecessary directory allocations.
- Achieved via a closure-based approach triggered during
readdirorgetdentscalls. - Although the cost of allocations doesn't seem too bad, I will look at this again at some point.
- Maybe achieved via a lending iterator type approach? See link for reference
3. Add additional filter criteria
- Implement features such as ownership tracking.
- Maybe use
NO_ATIMEto avoid disk writes, this has a lot of drawbacks however.