SharePoint provides a powerful object model to retrieve and manipulate data stored in SharePoint Lists. Its possible to query the data by retrieving all content from a list or view – or by executing a so called CAML (Collaborative Markup Language) Query
Real-Life GetItemById Problem
I’ve recently been working with a customer who faced performance problems with their custom developed web parts. The Web Parts allowed a user to view and manipulate account information which was stored in different SharePoint lists.It seemed the page got slower the more accounts where stored in the lists. When a user clicked to view the account details the information was queried and displayed. When we analyzed the request we immediatelly saw the problem.
The SPListItemCollection.GetItemById was used with the assumption that only the data for the requested Item was queried from the database. However – using GetItemById on the Items Property of an SPList object in fact queries ALL items from the database. Then the resultset is filtered in memory to only return the requested item.
Changing this request to a call to SPList.GetItems(camlQuery) improved the call performance tremendously.
Just with this change we improved the performance of the WebPart by more than 2 seconds.There are many blogs out there which discuss the correct usage of the SharePoint Data Interfaces. GetItem vs. GetItemById is a heavily discussed topic among others. The solutions presented on those blogs are basically the same as we have identified with this customer.
The most important thing for SharePoint developers is to really understand what’s going on within the Framework (SharePoint) when being used. Someone can really kill performance with inappropriate usage of the different query options that SharePoint provides.
Will post more SharePoint related Performance Topics