Speed up expensive IEnumerable<T> operation : <p>I am working on a C# library that recursively enumerates the subfolders of a remote share over the network. This is an expensive operation, and there may be thousands of folders to be traversed. The method that carries out this work for the client returns an <code>IEnumerable&lt;string&gt;</code>, and uses lazy evaluation (as is often the case with <code>IEnumerable&lt;T&gt;</code>, so the call itself returns very quickly, but then, when the client executes a <code>foreach</code> loop or a <code>Take()</code> call on the return value, things get pretty slow.</p>

<p>I am looking for approaches to speed this up. Some ideas include:</p>

<ol>
<li>Avoid lazy enumeration by making my library retrieve all items and store them in a <code>List&lt;string&gt;</code>, for example, before it is returned to the client. This would make the method call much slower, but iteration much faster.</li>
<li>Drop the functionality to enumerate all the subfolders, and require that the client specifies some kind of filter that limits the number of items to traverse.</li>
<li>Use an altogether different method to enumerate folders which avoids <code>IEnumerable&lt;T&gt;</code>.</li>
</ol>

<p>I have run out of ideas. What approach would you suggest to make this work, and fast? Thank you.</p>
