Project Description

This proof of concept is similar to the FastDirectoryEnumerator on CodeProject. That project uses unmanaged code to work around some of the performance limitations in the Directory.Getxxx methods, which are inherently inefficient due to the number of file system accesses that are performed when retrieving each file system entry.

DirectoryEnumeratorAsync uses managed code and leverages the new async/await features of .NET 4.5 to minimize blocking and ensuring that there is always a thread ready to execute.

If performing the test on fast local media with no contention (such as an SSD), it is possible that there may be no difference. However, when performing numerous accesses to resources where there are some measurable latency and/or contention, the time that is ordinarily spent blocking during those synchronous calls can instead be utilized by a ready thread.

The attached solution provides two simple tests of recursively enumerating a file system. A traditional synchronous and an asynchronous test using async/await. In our example when performing the test against a network file system over a standard Gigabit LAN, using async/await yielded a 20x performance improvement over the traditional synchronous method.

Last edited Nov 30, 2012 at 8:56 PM by GregAskew, version 3