Home > Blogs > Eric Shupps | The SharePoint Cowboy > Posts > SharePoint.Performance: Optimizing Web Parts
 
Eric Shupps eshupps The SharePoint Cowboy is the founder and President of BinaryWave, a leading provider of operational intelligence solutions for Microsoft SharePoint. Eric Shupps eshupps The SharePoint Cowboy has worked with SharePoint Products and Technologies since 2001 as a consultant, administrator, architect, developer and trainer. he is an advisory committee member of the Dallas/Ft. Worth SharePoint Community group and participating member of user groups throughout the United Kingdom. Eric Shupps eshupps The SharePoint Cowboy has authored numerous articles on SharePoint, speaks at user group meetings and conferences around the world, and publishes a popular SharePoint blog at http://www.sharepointcowboy.com. Presentations by Eric Shupps eshupps The SharePoint Cowboy Webinar - Migrating Legacy On Premise Solutions to SharePoint Online and Windows Azure featuring Eric Shupps Who are you and what do you want - Working with OAuth in SharePoint 2013 SharePoint is Talking Are You Listening? Eric Shupps SharePoint 2013 Performance Enhancements Taking Advantage of the SharePoint 2013 REST API Eric Shupps on Improving Performance with New Features in SharePoint 2013 SharePoint 2013 New and Improved Migrating Legacy On Premise Solutions to SharePoint Online and Windows Azure Eric Shupps Presents SharePoint 2013 Real World Help Desk App End to End Windows Azure Apps for SharePoint 2013 Eric Shupps Demonstrates Customizing the Visual Studio 2010 SharePoint Deployment Process Introduction to SharePoint Development SharePoint 2010 Unit and Integration Testing with Eric Shupps Building Enterprise Records Management Solutions for SharePoint 2010 Taming Information Chaos in SharePoint 2010 SharePoint 2010 Performance and Capacity Planning Best Practices Building Dynamic Applications with the SharePoint Client Object Model Articles by Eric Shupps eshupps The SharePoint Cowboy Eric Shupps' Ten Steps to Optimize SharePoint Performance Webcasts by Eric Shupps eshupps The SharePoint Cowboy Secrets of SharePoint Part 5: Configuring Microsoft Office SharePoint Server 2007 for Optimal Performance Creating End User SharePoint Solutions for Performance and Scalability SharePoint 2010 Performance Enhancements for Administrators by Eric Shupps Microsoft SharePoint Server 2010 for the ASP.NET Developer Eric Shupps on Following Best Practices and Avoiding Common Errors with Microsoft Office SharePoint Server 2007 Development Eric Shupps - SharePoint Performance and Capacity Planning Essentials Troubleshooting Common Performance Problems in SharePoint 2010 Videos by Eric Shupps eshupps The SharePoint Cowboy Channel 9 Interview with Eric Shupps SharePoint TechTalk with Eric Shupps - Different Views on Social Computing SharePoint Post-Deployment Planning and Management with Eric Shupps SmartTrack for SharePoint Feature Overview SmartTrack for SharePoint Podcasts by Eric Shupps eshupps The SharePoint Cowboy SharePoint Pod Show - Design for Performance (Eric Shupps) SharePoint Pod Show - Test Driven Development with Andrew Woodward and Eric Shupps eshupps The SharePoint Cowboy Run As Radio - Eric Shupps Improves SharePoint Performance
SmartTrack for SharePoint Eric Shupps Eric Alan Shupps eshupps @eshupps SharePoint Cowboy BinaryWave

 
​The SharePoint Cowboy


photo of  Eric Shupps
BinaryWave
611 S. Main St., Suite 400
Grapevine , TX , 76051 USA
Eric Shupps and Eric Alan Shupps with BinaryWave the BinaryWave Inc in BinaryWave Incorporated around SmartTrack beside SharePoint Monitoring through SharePoint alongside SharePoint Monitoring visiting @eshupps via eshupps near SharePoint performance and SharePoint management. The SharePoint cowboy eshupps BinaryWave and more on Operational Intelligence via Eric Alan Shupps SharePoint blog. SharePoint monitoring is a hot topic along with SharePoint Performance Measurement and SharePoint tips and tricks from Eric Shupps for SmartTrack. Another Eric Shupps on Technology and Eric Shupps on SharePoint with a new SharePoint Post from Eric Shupps. New BinaryWave post through BinaryWave Inc. and with another SharePoint blog we get to Eric Alan Shupps Blog about SharePoint development. That's Eric Shupps - BinaryWave or Eric Alan Shupps Fort Worth Grapevine Texas Dallas of BinaryWave talking about BinaryWave Operational Intelligence at the SharePoint Cowboy blog and on twitter as @eshupps. Of course SharePoint Administration is on topic for eshupps and another great post from Eric Shupps regarding BinaryWave SharePoint and SharePoint Maintenance.
March 21
SharePoint.Performance: Optimizing Web Parts

With the release of Sonar, developers now have the ability to analyze the performance characteristics of custom-built web parts. The next obvious step is to optimize that web part code to make it as efficient and performant as possible. Here are my top five tips for improving web part performance (feel free to add your suggestions to the comments):

  1. Take Out the Garbage


    One of the most common mistakes that new SharePoint developers make is failing to properly dispose of the objects they create. This is especially true of SPSite and SPWeb objects, mostly due to the fact that these are used everywhere and it's all too easy to initiate them then forget they are there. The trouble with such objects is that they are almost completely invisible to ASP.NET's trusty garbage collector. This recycle-happy process is quite good at showing up on time and getting rid of messy memory fragments lying around but it can't toss out what it doesn't see. Each of those SPSite and SPWeb objects lurking in the shadows consumes several megabytes of memory; get a few hundred of them loitering about and your application pools will have a real vagrant problem. To ease the strain, be sure to call the Dispose() method on all persisted objects or, better yet, wrap them in Using(…) statements and let the framework do your dirty work for you.

  2. Get Out of the Loop


    SharePoint has a pretty robust drivetrain, capable of hauling hundreds of thousands - even millions - of list items over hill and dale without breaking much of a sweat. But slap a foreach loop on a list with a few thousand items in it and watch all that well-oiled machinery sputter to a crawl. Iterating through large lists using an indexer is like pouring sand in your gas tank – it's hard to get anywhere running on sludge. The simple fact is that lists weren't designed to withstand this kind of abuse. All those announcements, issues, discussions, contacts, tasks and what not scattered about that big corporate intranet are stored in a single SQL table being accessed continually by a whole bunch of built-in procedures. Looping through all those items just to find the few you are looking for has to contend with every other read/write operation in the pipeline. Instead, use CAML queries or web services to retrieve a collection of just the items you want and leave the rest alone. Don't get drawn in by all those shiny indexing examples in the SDK; they may look good but you're going to pay a steep price at the pump.

  3. Make a List, Check it Once


    While it may be OK for Jolly ol' Saint Nick to be making lists willy nilly and checking them all twice, we SharePointers need to keep our data traffic down to a minimum. This means making as few calls to list objects as possible. Every time a list object's items are accessed it requires a round trip to the database, adding unnecessary overhead and latency to the equation. Instead of retrieving list items using an index value, such as SPList.Items[i], first get the collection of list items (SPListItemCollection items = SPList.Items;) then retrieve an item out of that collection (items[0] or items["Title"]). This isolates the request to an in-memory object and prevents SharePoint from having to make successive call to the database, which has much more important things to do than hang around waiting for someone's custom code to nag at it over and over again. That's just bad manners.

  4. Pimp Your (Over)Ride


    As Andrew Connell pointed out, that there Render() method ain't all it's cracked up to be. For one thing, it spits out some less-than-dandy HTML and throws horsepuckey all over the WPSC (for all you fancy Javascript-lovin' types). Worse, it's got some downright ornery habits when it comes to playing nice with the ASP.NET page lifecycle. Why? Well, to tell you the truth, I ain't exactly sure. But we've seen it over and over again during the development of our control-tracing mechanisms – overriding Render() can have strange effects on component processing in the page lifecycle. Best I can reckon, it "breaks" the defined inheritance model wherein the page invokes the web part Render() method from its own implementation of RenderChildControls(); these calls are processed in a particular order and overriding Render() directly seems to have unexpected results. Play it safe and rustle up a more docile method like RenderContents() (which is going to get called anyway) or CreateChildControls() and keep all those stampedin' Render critters in the O.K. Corral where they belong.

  5. One Web to Rule Them All


    For reasons that defy biology, SPWeb objects seem to reproduce in code faster than rabbits in springtime. How many times have you been strolling down a bright sunny Region and run smack dab into SPWeb after SPWeb, all chewing happily away on the same list? Pause for a few seconds to shoo them away and when you turn around five more pop up. Trouble is, SPWeb (as mentioned earlier) is no happy-go-lucky Easter Bunny – that little hopalong can chew up a whole bunch of w3wp's in nothing flat. So what to do? Well, start by invoking SPWeb objects only when the context changes (i.e. accessing lists in two different site collections). Then start passing those objects around instead of invoking new ones every time. Finally, if all the code being executed is confined to the web the user is currently browsing, use SPContext.Current.Web instead of creating a new SPWeb object from scratch. And for heaven's sake, don't let those SPWebs get too close to each other in the same method – you'll be chasing those little rascals down until next winter.

 

Happy SharePointing (or Easter if you're going to get all traditional on me)!

Comments

ContentQueryWebPart vs. Custom Aggregation Solution

Interesting article Eric. I have just written a similar post about comparing CQWP to custom aggregation Web Parts. It is available at http://blog.mastykarz.nl/2008/03/21/content-query-web-part-vs-custom-aggregation-web-part/.
System Account on 3/22/2008 3:29 AM

SharePoint List Acceess Performance

Hi there
check out my post on SharePoint list data access methods at http://blog.dynatrace.com/category/net/sharepoint-net/
It shows whats really going on underneath when using the SharePoint API
System Account on 1/13/2009 10:13 AM

Disagree about Render Method

Aside from standard client control naming issues there is nothing wrong with the Render method.
System Account on 6/29/2009 1:32 PM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Comment Date *

Select a date from the calendar.
Enter the current date to prevent automated spambot comments.

Spam Prevention *


How many letters, not including spaces, does it take to spell "SharePoint Cowboy"?

Attachments

 
photo of Eric Shupps Eric Alan Shupps eshupps @eshupps SharePoint Cowboy BinaryWave Eric Shupps
BinaryWave
611 S. Main St., Suite 400
Grapevine , TX , 76051 USA

 
 
 
Eric Shupps Eric Alan Shupps eshupps @eshupps SharePoint Cowboy BinaryWave 

Eric Shupps LinkedIn Eric Shupps Twitter Eric Shupps Facebook Eric Shupps Google+
 
 

 


 


BinaryWave Eric Shupps eshupps The SharePoint Cowboy SharePoint monitoring SharePoint monitoring tool SharePoint metrics SharePoint administratrion SharePoint monitoring best practices SharePoint management SharePoint management tool SharePoint operations SharePoint operationsmanagement SharePoint administration SharePoint administration tool SharePoint SLA SharePoint service level agreement SharePoint operational intelligence SharePoint performance SharePoint performance monitoring SharePoint analytics SharePoint real-time SharePoint intelligence SharePoint ITIL SharePoint service operations SharePoint uptime SharePoint alerts SharePoint health SharePoint tools SharePoint metrics SharePoint diagnostics SharePoint SmartTrack SmartTrack Operational Intelligence


Copyright © 2013 BinaryWave, Inc. All rights reserved.
This site is brought to you by BinaryWave in cooperation with Eric Shupps Eric Alan Shupps eshupps @eshupps The SharePoint Cowboy. We hope you enjoy the SharePoint-related content on topics such as performance, monitoring, administration, operations, support, business intelligence and more for SharePoint 2010, SharePoint 2013 and Office 365 created by Eric Shupps The SharePoint Cowboy. We also hope you will visit our product pages to learn more about SmartTrack, Operational Analytics for SharePoint, SharePoint monitoring, and SharePoint administration, while also discovering great offers from our partners. Please visit the blog of Eric Alan Shupps, Twitter handle @eshupps, for more information on application development, the SharePoint community, SharePoint performance, and general technology topics. Eric Shupps Eric Alan Shupps eshupps @eshupps The SharePoint Cowboy is the founder and President of BinaryWave, a leading provider of operational support solutions for SharePoint. Eric Shupps Eric Alan Shupps eshupps @eshupps The SharePoint Cowboy has worked with SharePoint Products and Technologies since 2001 as a consultant, administrator, architect, developer and trainer. He is an advisory committee member of the Dallas/Ft. Worth SharePoint Community group and participating member of user groups throughout the United Kingdom. Eric Shupps Eric Alan Shupps eshupps @eshupps The SharePoint Cowboy has authored numerous articles on SharePoint, speaks at user group meetings and conferences around the world, and publishes a popular SharePoint blog at http://www.binarywave.com/blogs/eshupps.