Fast Directory Listing on Linux
61–70 of 75 posts
Re: Fast Directory Listing on Linux
#62> returning vector is an unaffordable convenience. Not anymore since C++11. Reusing vector storage is good, but you can still use move on parameter and not the reference. Although, in this case, reference is probably easier to write.
I think he was concerned about the cost of allocating separate strings that go into the vector.
C++11 didn't make returning the vector in this function faster because it's written in a way to take advantage of RVO. It did make growing the vector faster though -- individual strings now get moved instead of copied.
Re: Fast Directory Listing on Linux
#63Re: Fast Directory Listing on Linux
#64You can get faster than memcmp by rolling your own SSE/AVX compare. memcmp typically has a few branches and instruction cachelines of just trying to verify that it's running on aligned memory and checking how aligned (ie 8byte stride vs 64 byte stride). All that can be skipped with a for-loop of intrinsics if you the programmer know alignment characteristics the compiler cannot infer.
Re: Fast Directory Listing on Linux
#65I wonder how this compares to filesystem traversal APIs like fts/ftw?
fts and ftw are glibc wrappers over glibc wrappers that I had to bypass for better performance. They are made for convenience, not for speed.
I was looking at fts because there exists a BSD licensed implementation of nftw in terms of fts; I was researching the possibility of creating a semantically extended/enriched version of nftw, without coding it entirely from scratch. So I plonked that implementation into my program and, lo and behold, error message from glibc's fts header file about not supporting 64 bit file offsets.
Re: Fast Directory Listing on Linux
#66Re: Fast Directory Listing on Linux
#67A really important optimization when scanning directories is to avoid doing the stat on each object just to get its type. On Linux, the struct dirent has a d_type (not specified by POSIX and not supported by all filesystems) which forward the type of the object from the inode to the directory entry. When portable programs that use stat to get basic type information (like "is this a directory or a regular file") are c…
> [...] every element in entries has d_type at offset -1. This can be useful to the callers that need to distinguish between regular files and directories (gitstatusd, in fact, needs this). Note how ListDir() implements this feature at zero cost, as a lucky accident of dirent64_t memory layout.
Re: Fast Directory Listing on Linux
#68What about using nftw directly instead of opendir/readdir
Re: Fast Directory Listing on Linux
#69Earlier quoted context omitted.
inotify requires you to hold open fds for all the dirs and files you're watching iirc, so in repos that large, you'll be crushed by the file-descriptor-per-process limit.
It doesn't, you might need to tweak its limits via /proc/sys/fs/inotify/max_* on such repositories, but those limits are not the same as the much lower open FD limits (as in ulimit -n ...).
Re: Fast Directory Listing on Linux
#70A really important optimization when scanning directories is to avoid doing the stat on each object just to get its type. On Linux, the struct dirent has a d_type (not specified by POSIX and not supported by all filesystems) which forward the type of the object from the inode to the directory entry. When portable programs that use stat to get basic type information (like "is this a directory or a regular file") are c…