-
Notifications
You must be signed in to change notification settings - Fork 191
Openness to a low-level getdents64 directory iterator? #451
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
Comments
Oh, I should also mention that while the zero-compromise implementation is ~15% faster overall, it's actually a whopping 5x faster in userspace where we can control the code. |
Yes, we're interested! One consideration here is that one of the main users of rustix's The other is that in the linked API, the main example shows a fixed-sized buffer with size 2048. I'd prefer to avoid an API where users have magic buffer sizes in their code. If we end up with two directory iteration APIs, perhaps the lower-level one can drop support for resizing and just take a |
Yup, that's pretty much the approach I took. In theory, the higher level API should be able to be built on top of one that uses lifetimes by to_owned-ing everything when necessary.
I think providing a suggested constant for the buffer size is a great idea since we can do some benchmarking and find the optimal one. That said, we'd still want to accept slices so as not to prevent users from doing buffer resizing if they so desire (also slices work great with Vec::spare_capacity_mut or a small-ish stack buffer). |
I'll get to this hopefully in the next few days or over the weekend. 👍 |
The stdlib and nix use libc's readdir to do directory iteration while rustix uses getdents, all of which are slow. readdir is C, so it includes locking to support multithreading (which I'm pretty sure isn't necessary in rust due to the ownership model). nix is faster than the stdlib because it doesn't allocate anything while iterating whereas the stdlib allocates path names. rustix suffers from the same allocation problem, but is quite a bit faster than nix or the stdlib because it uses getdents.
A zero-compromise getdents implementation is still ~15% faster than rustix:
I have an implementation open for nix: nix-rust/nix#1856. The API requires a buffer and makes you handle resizing if you need that. The API is currently safe, but I need to see what happens if you seek a directory and if that's worth an unsafe (rustix's existing Dir should have the same problem of potentially garbage offsets since you can dup fds). I can explain more around the reasoning of the API if there's interest.
Would you guys also be interested? If so, I'll look into opening up a PR in the next few days.
The text was updated successfully, but these errors were encountered: