Working with SPList was found that upon receipt of a list item on Guid of SPListItemCollection.this [Guid] took a lot of time on a large collection.
It looked like this:
var uniqId = new Guid(/* get GUID somehow */);
SPList list = /* get list somehow */;
SPListItem anItem = list.Items[uniqId];
But it turns out, there is another way to get a list item SPList.GetItemByUniqueId(Guid uniqueId). Using this method does not arise for the delay in large collections. To determine the differences we use the reflector, and see how to implement a method to obtain an element in the collection for SPListItemCollection in Microsoft.SharePoint.dll. That's what we see in SPListItemCollection.this[Guid]:
public SPListItem this[Guid uniqueId]
{
get
{
this.EnsureListItemsData();
this.EnsureFieldMap();
int iIndex = 0;
int columnNumber = this.m_mapFields.GetColumnNumber("UniqueId");
string str2 = uniqueId.ToString("B").ToLower();
while (true)
{
if (iIndex >= this.m_iRowCount)
{
throw new ArgumentException();
}
string str = ((string) this.m_arrItemsData[columnNumber, iIndex]).ToLower();
int num3 = SPUtility.StsBinaryCompareIndexOf(str, ";#");
if ((num3 > 0) && (str.Substring(num3 + 2) == str2))
{
this.EnsureListItemIsValid(iIndex);
if (this.m_iColection == null)
{
return new SPListItem(this, iIndex);
}
return this.m_iColection.ItemFactory(iIndex);
}
iIndex++;
}
}
}
As we can see the contents of the entire collection moves an element by element, each element is calculated with a given match GUID'a. More collection - the longer work.
And now look at the implementation of the method GetItemByUniqueId for SPList:
public SPListItem GetItemByUniqueId(Guid uniqueId)
{
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name=\"UniqueId\"></FieldRef><Value Type=\"Guid\">" + uniqueId.ToString("B") +"</Value></Eq></Where>";
query.ViewAttributes = "Scope=\"RecursiveAll\" ModerationType=\"Moderator\"";
query.MeetingInstanceId = -2;
query.QueryOpt = SPQuery.SPQueryOpt.None | SPQuery.SPQueryOpt.UniqueId;
SPListItemCollection items = this.GetItems(query);
if (items.Count != 0)
{
return items[0];
}
while (!(this.ID == this.Lists.Web.UserInfoListId))
{
throw new ArgumentException();
}
throw new ArgumentException(SPResource.GetString("CannotFindUser", new object[0]));
}
Here, using SPQuery, we obtain directly the very record without sorting the collection.
Conclusion: The use of large lists SPList.Items[Guid] - long, unproductive. Better to use SPList.getItemByUniqueId(Guid);