Return to doc.sitecore.com

  Programming
Prev Next

This section is dedicated to best programming practices, speeding up Sitecore installation and debugging in Sitecore.

1.  Programming Practices

Data Structuring can influence the performance. If the logic for home page news articles is to present the latest three, the logic of looking for articles structured as /year/month/day/article is faster than sorting a large number of articles stored directly under /news.

1.1.  Speeding up Sitecore Development Installation

There are a number of options to speed up the Sitecore development installation:

1.2.  Link Database

Sometimes it is required to get all Items in the database based on a given template. Iterating through the entire database may be a very expensive operation though.

However in this particular case, we can resort to the Link database. Link database is used by Sitecore to resolve all the linking issues - what referrers and what references the Item has. And if an item is based on a template, it also counts as a reference from the item to the template. The solution then is very simple: get all the referrers for a given template item.

Below you can see how Link Database is used in the RSS module architecture:

private static Item[] GetFeedsInDatabase(Database database, Language language)
{
   TemplateItem feedTemplate
= database.Templates[Constants.FeedTemplateID];
  
if (feedTemplate == null)
   {
      
return null;
   }
  
// Get all items refering to the feed template
   ItemLink[] links = Globals.LinkDatabase.GetReferers(feedTemplate.InnerItem);
  
if (links == null)
   {
      
return null;
   }
   ArrayList result
= new ArrayList(links.Length);
  
// and filter the referers - we dont need to include masters
   foreach(ItemLink link in links)
   {
      
if (link.SourceDatabaseName == database.Name)
      {
         Item item
= database.Items[link.SourceItemID, language];
        
if ((item != null) && (IsMaster(item) == false))
         {
            result.Add(item);
         }
      }
   }
  
return (Item[])result.ToArray(typeof(Item));
}

See also:

2.  Optimize VS 2005

If you are finding that Visual Studio 2005 if running slowly you can take these steps to improve the speed of your IDE. Here are the tips:

Then optimize your environment itself:

These and other useful features for optimising VS2005 were listed from an article published on a Sitecore blog recently. to see the posting click on the following link.

http://sitecore.alexiasoft.nl/2007/10/25/increasing-productivity-with-visual-studio-2005/

3.  Optimize XSL

You should avoid using the descendant axes (//, etc.).

Because of a memory leak in the 1.1 .NET framework (http://support.microsoft.com/default.html?scid=KB;EN-US;Q316775) which can lead to increased CPU usage, implement .NET extensions instead of script embedded in the XSL code with msxml:script. .NET 2.0 may correct this issue.  Implementing XSL Extensions is described at Creating Sitecore Extension Function.

4.  Convert Underperforming XSL Renderings to .NET

Certain operations can be completed much more efficiently in .NET than in XSL. Use Sitecore’s browser-based debugger to identify poorly performing code for migration to pure .NET.

Invoking XSL may be more expensive in .NET than executing native .NET code.  If possible, certain XSL renderings, especially those which consume a great deal of resources or can only be cached under limited conditions should be converted to .NET method renderings, sublayouts or web controls.  Expensive XSL code can be converted to .NET extension controls and functions.

5.  Static HTML Generation

Static generation should only be considered as a last resort as it defeats much of the value of implementing Sitecore.

 

6.  Debugging

In addition to debuggers such as the one provided with Microsoft Visual Studio .NET, Sitecore provides a browser-based debugger which can be activated in Layout Studio and by choosing Start from the Debug menu, through http://server?sc=debug=1 or by creating a menu item in the core database such as through the debug package available from http://groups.yahoo.com/group/sitecore/files. Use Sitecore’s debugger to determine why pages are not rendering correctly and which rendering components are consuming inordinate resources.  Use the Microsoft Visual Studio .NET debugger for line-level debugging.  See http://sdn.sitecore.net/SDN5/Articles/API/Debugging%20Your%20Sitecore%20Code.html for specifics on debugging with Sitecore.

6.1.  Accessing Sitecore Debugging More Easily

The Visual Studio .NET debugger is great for debugging .NET at the code level, but Sitecore’s browser-based debugger is often useful for performance analysis and high-level investigation such as looking at the output of an entire page or individual rendering.  The debugger requires authentication as an administrator and provides some settings through /web.config (search for “debug”).  There are at least two ways to access the debugger:

To add a Debug button to the bottom of the Sitecore menu, install the package or follow these steps:

Refresh the desktop and a Debug item should appear at the bottom of the Sitecore menu.

You can download a ready-made package which adds a Debug button into Sitecore menu here .


Prev Next