Sitecore Core Development

Tuesday, September 06, 2005

Optimizing

A natural phase of software development is optimizing and Sitecore version 5 has just passed through the first iteration of optimizing - probably one of many to come.

My greatest task was to optimize the Sheer UI and the Content Editor was the main problem. After using the dotTrace profiler from JetBrains, it became apparent that the performance of the Content Editor depended greatly on the number of web controls on the page. When the number exceeded about 200 controls performance decreased drastically. This is not problem with Sitecore, but more with ASP.NET as it seems that ASP.NET scales pourly. The Content Editor has about 1.200 webcontrols when all sections are expanded, so we quickly realised the we had to reduce the number of webcontrol on the page.

ASP.NET uses the runat="server" attribute to identify tag that should be converted into web controls. It is therefore a manual process to create a web control in a standard ASP.NET page and it is therefore unlikely that there will be many web controls.

The Content Editor is however built using XML Controls in which every tag is converted into a web controls. Naturally the creates a lot more web controls than ASP.NET normally does.

In ASP.NET everything that is not marked by a runat="server" attribute is converted into a LiteralControl. We thought about using the same approach. We would convert every tag that did not have an ID into a LiteralControl and then merge adjacent literal controls into a single control. Unfortunately this was working and we had to use a more simple method.

The solution was to use an attribute that was sort of the opposite of the runat="server" attribute - an attribute that describes that a web control is not needed on the server once it has been rendered. We settled on the name renderas="literal", which means that the web control and any subcontrols are rendered as a LiteralControl. When the page renderes, ClientPage walks the control tree and any web controls that have the renderas="literal" are rendered and replaced by a LiteralControl containing the result. Afterwards it is not possible to use the web controls in Sheer UI as it has now been replaced by the LiteralControl.

When placed with care, the number of web controls is reduced dramatically. The Content Editor went from 1.200 web controls to about 200 and this has greatly improved the performance.

0 Comments:

Post a Comment

<< Home