18 04 2008
SharePoint: Get better performance when getting list items
Another day, another solved mystery. Developers have interesting lifes as long as there are problems to solve. Another surprise from SharePoint – how to bog server down using only couple of lines of code? Of course, I have solution too that eliminates the issue.
Let’s say you have large document library with many documents (let’s say there is a little bit more than 90.000 documents). Some of them are versioned, some of them are new and so on. Now, let’s say you have to manipulate documents in your code and you have to find document with specific ID. The document, if it exists, is given to you as SPListItem:
SPListItem item = list[new Guid(itemGuidString)];
When you try something like this the code may run fast – as long as you have few documents you don’t have any performance issues. But if you have about 90.000 documents than retrieveing one document as list item may take about 1:00 or 1:30 minutes with no problems. And good server you are using is not saving you this time.
What you have to do is to ask documents by items’s unique ID from SPList.
SPListItem item = list.GetItemByUniqueId(new Guid(itemGuidString));
If you ask documents this way then documents are retrieved through CAML query and you save on performance a lot.