Fast Directory Listing on Linux
Combining these ideas with the fact that file names on Linux are at most 255 bytes long, we can invoke like this:
And then compare entries like this:
This version doesn’t give any speedup compared to the previous but it opens an avenue for another optimization. Through a series of incremental improvements we’ve sped up directory listing by 43.3% compared to a naive implementation (v1) and 27.2% compared to a reasonable implementation that a seasoned C/C++ practitioner might write (v2). If we assume that it makes the minimum possible number of system calls and these calls are optimal, it puts the upper bound on possible future performance improvements at just 3%.
Source: github.com