9

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?

2

2 Answers 2

14

web.Lists[guid] is the fastest.

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

1
  • web.Lists[guid] - is not fastest. For some reason, TryGetList is faster!
    – Aviw
    Apr 29, 2014 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.

2
  • Does web.Lists[guid] load all the site lists into memory before accessing it like web.Lists.TryGetList() does? Mar 29, 2012 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.) Mar 29, 2012 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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