Monday, December 10, 2007

XML to HTML Transforming

During some recent performance tuning on a ASP.NET web app, I saw a noticable cpu spike whenever the app did a server-side XML-to-HTML transform. The function in question was to essentially render a series of dynamic forms to HTML (where the number and size of the forms varied).

The code simply used streams with an XPathDocument and XslCompiledTransform to transform potentially large amounts of XML (and large XSLTs) into HTML on-the-fly.

After reviewing the code, a coworker had the idea of simply moving the transform down to the client. I honestly don't know why we never thought of that in the first place...

But anyway, we quickly threw together some javascript making use of ActiveXObjects XMLHTTP and XMLDOM and modified our server-side code to just send down the raw XML.

The results yielded noticable performance gains for both client and server. The client generally saw page loading improve by 30%-50% depending on the machine - plus we had the added benefit of reducing the cpu load on the webserver.

The only time the change actually hurt the client was when there was a considerable amount of XML to transform (many MB of data) - which actually would have been faster done server-side - but statistically speaking that was going to be a pretty rare occurance.

0 comments:

Post a Comment