April 6th, 2006

It's more efficient when you buy in bulk

The Windows XP kernel does not turn every call into FindNextFile into a packet on the network. Rather, the first time an application calls FindNextFile, it issues a bulk query to the server and returns the first result to the application. Thereafter, when an application calls FindNextFile, it returns the next result from the buffer. If the buffer is empty, then FindNextFile issues a new bulk query to re-fill the buffer. This is a significant performance improvement when reading the entire contents of large directories because it reduces the number of round trips to the server. We’ll see next time that the gain can be quite significant on certain types of servers.

But it also means that the suggestion of “Well, why not ask for 101 files and see if you get an error” won’t help any. (Actually I think the magic number was really 128, not 100, but let’s keep calling it 100 since that’s what I started with.) The number 100 was not some magic value on the server. That number was actually our own unwitting choice: The bulk query asks for 100 files at a time! If we changed the bulk query to ask for 101 files, then the problem would just appear at the 102nd file.

Topics
Other

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.