|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
Performance Tuning the Work Item Tracking Object Model
The work item object model offers several advanced features for optimizing performance. These features enable the product to improve the bulk editing performance of Microsoft Excel and Microsoft Project integration features as described in the following list.
Paging and lazy evaluation occurs ons returned by a query. When you execute a query, the system returns only the fields selected in the query expression as part of the WorkItemCollection. For example, the query in the following example selects the Title field from a group of work items. The WorkItemCollection returned from this query will only include the selected “Title” field values for the contained s. Only when you read or edit other fields on the WorkItem, will the system make a round-trip to fetch the other field values.
SELECT System.Title FROM Workitems WHERE (ID < 1000)
Additionally, the selected fields returned as part of the WorkItemCollection are paged in chunks. You can set the page size between 50 and 200 by using theproperty to tune performance, as needed.
Because of the paging and lazy evaluation scheme discussed earlier, viewing or editing unpaged fields on a WorkItem in a WorkItemCollection will cause an additional round-trip. This round-trip retrieves all the additional work item data that is not paged in as part of the query. This operation can be expensive.
Consumers can callon a WorkItem to minimize this overhead. You can then view and edit most of the fields on the WorkItem, but the object model optimizes to send a minimal set of data over the network.
It is sometimes desirable to retrieve a specific set of WorkItems directly by ID if you know the IDs in advance. To do this, use the method in the following example. It takes in a batch collection that specifies the IDs and revisions of the desired WorkItems and a query string that specifies thes to page.
public WorkItemCollection Query(BatchReadParameterCollection batchReadParams, string wiql)
This method minimizes the round-trips used for a query, especially if the goal is to get a specific revision of each WorkItem. The following example specifies the series of calls in which you must specify IDs and revisions of work items.
Run a query for the desired WorkItems. This returns a collection of the latests for the WorkItems.
Open each WorkItem in the returned WorkItemCollection.
For each WorkItem in the returned collection, open the desired Revision from its.
Steps 1 and 2 earlier require round-trips to the server. For many WorkItems, the number of round-trips increases linearly.
By using the batch read version of the, the system returns the collection of specified work item revisions with a constant order of round-trips.
Every time you save a work item to Team Foundation Server, you generate a round-trip operation between the work item object model and the server. To minimize the round-trips when saving several work items, use themethod.
public BatchSaveError BatchSave(WorkItem  workitems)
The method saves an array of WorkItems with far fewer round-trips.