XamlWriter Performance: Update

September 18, 2006

About a month ago, I blogged about Xaml serialization, and pointed out a discrepancy between the performance of XamlReader and XamlWriter.  Simply put, serializing WPF objects with XamlWriter is much slower than loading the same objects with XamlReader.  (as of the RC1 bits)  This is somewhat understandable considering how important the Xaml parser is to the framework, but at 5 to 9 times slower, I pointed out that XamlWriter could use some serious love.

Unfortunately, however, I was informed that XamlWriter optimizations were not going to make the release window.

Enter Rob Relyea, Program Manager in the WPF group at Microsoft.  Not content to let ‘sucky’ performance prevail, Rob whipped up a sample implementation of XamlWriter using the underlying APIs.  To make a long story short, it’s twice as fast as the built in XamlWriter, and in my testing seems to work well with a wide variety of WPF objects.  Thumbs up from the developer community Rob – I’m glad Microsoft has people on the job who have obvious passion for what they’re doing.

The code sample is not complete, but it should be trivial to add your own implementation of the methods you require.  The code can be found in this thread in the MSDN forums.