8

I want to know the fastest way to access a list. Would it be:

            SPWeb web = site.RootWeb;
            SPList activityListFromUrl = web.GetList("/Lists/ActivityList");

or:

            SPWeb web = site.RootWeb;
            SPList activityListFromGuid = web.Lists[new Guid("aaa-aaa-aaa-aaa")];

or perhaps some other way?

13

web.Lists[guid] is the fastest.

web.GetList(url) calls a couple of methods to get the guid and then returns web.Lists[guid]

  • web.Lists[guid] - is not fastest. For some reason, TryGetList is faster! – Aviw Apr 29 '14 at 5:30
0

The only way to definitively answer "faster" type questions is to test in your environment.

Your farm (hardware, network, etc.) is going to be different than everybody else. So any advice you get will not apply to your configuration.

  • Does web.Lists[guid] load all the site lists into memory before accessing it like web.Lists.TryGetList() does? – Meyer Denney Mar 29 '12 at 16:11
  • No matter the answer to the question, performance can only be measured by doing actual measurements. (And the answer could be determined by reflecting those methods.) – Paul Schaeflein Mar 29 '12 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.