TFS 2010 API - Iterating through list of changesets returned in QueryHistory is way too slow

6.7k views Asked by At

Long story short. After profiling, this command takes 0,1% of the processing

var ChangesetList = TFSConnection.GetInstance().GetVersionControl().QueryHistory
    (Path, VersionSpec.Latest,0, RecursionType.Full, "", null, 
    VersionSpec.Latest, Int32.MaxValue,true, false);

This one, 65,7%. (funny thing, all the processing inside consumes only 3%)

foreach (Changeset changeset in ChangesetList)

It takes several seconds until I get my list... What is happening? Why is it so slow iterating through the list?

Is there any faster way to do this ?

Edit: Plus, why can't I convert it directly to a List<Changeset> ?

3

There are 3 answers

0
marste On BEST ANSWER

The call to VersionControlServer.QueryHistory returns an IEnumerable, so I assume it's like in LINQ to Objects and the actual query is executed as soon as you iterate over the IEnumerable (keyword: deferred execution).

You can't assign the result to an List because the return value is the non generic Version of IEnumerable. Calling Cast<Changeset>() or OfType<Changeset>() on the result returns a generic IEnumerable<Changeset>. After that you can call ToList() and get a List<Changeset>. ToList() iterates over the IEnumerable<T> so it's like the foreach and takes most of the time.

The methods I mentioned are extension methods and are located in the System.Linq namespace.

0
Robaticus On

QueryHistory lazy loads the collection. That is to say, that it doesn't actually execute your query until you try to iterate through it.

0
Chris On

the boolean "include changes" is taking the time... If you do not include the changes and only the metadata of the changesets the query is very fast

so the query should look like this:

var ChangesetList = TFSConnection.GetInstance().GetVersionControl().QueryHistory     (Path, VersionSpec.Latest,0, RecursionType.Full, "", null, VersionSpec.Latest, Int32.MaxValue,**false,** false);