Tired of waisting expensive CPU cycles? Waiting for ages for your site to load? Continue reading!
Sharepoint can be a great platform for starting custom development. The SharePoint API puts us (almost) completely in control. However, beautiull on the outside, it is hardly ever transparent for what is happening on the insde.
During my latest project we faced mutiple issues regarding performance optimization. This article will take a look at some of the interesting and gives a workaround.
Suppose we would want to build a custom navigation menu. To give us a complete collection of all available SPWeb´s, perfectly suited for our navigation class, we like to use the function SPSite.Allwebs().
Now here is an unharmful SharePoint call. Or isn´t it...?
Though it performed nicely on our testing environment, we encountered huge performance issues on production. The thing is, the more webs a site has, the longer the call will take. When dealing with around 300 SPWeb´s, each page load would start to take ages (well it might have been seconds, but the server CPU was at full blast).
To avoid this, I´d suggest caching. Preferably (but optional) using the Microsft Enterprise Library. Loop thru the SPWeb collection, copy all the information required into a DataTable object, and place that into the cache. Finally, just add some code to see if you have the DataTable in cache, and if so, skip the expensive AllWebs call.
Enjoy the new record load times. Your visitors wil get so excited they´d wanna hug you and squeeze you.