May 2009

WPF is Like a Fat Super Hero

by Steve Wortham
It's slow to start up, but once it gets going it really moves.

For those that don't know, WPF stands for Windows Presentation Foundation. It is Microsoft's latest and greatest .NET Windows user interface development architecture, aimed to replace Windows Forms. Having built a fairly large Windows Forms app in .NET 2.0 Windows Forms before, I thought WPF would be an easy transition for me. That hasn't exactly been the case -- a lot has changed.

However, now that I'm a little more comfortable with WPF, I've come to certain conclusions about it. First of all, I'm loving the flexibility. In some ways it's like Flash development and I loved Flash development when I did it for a bunch of projects between 2001 and 2005. Being able to apply custom gradients, draw custom shapes and buttons, and animate objects all in vector form is pretty cool.

But to me the best thing about WPF, and the thing that I think often goes under-appreciated, is how it takes advantage of the GPU in your video card to off-load some of the UI processing from your CPU. As a former OpenGL 3D programming hobbyist, I can really appreciate the power of the GPU. My $100 video card at home has 112 cores each running at 1.5 GHz. That's essentially like 112 processors that (when I'm not playing a video game) are never used to their potential. So Microsoft has finally recognized how much processing power are in these massively powerful video cards that are now commonplace in even the most basic new PC's and they've made WPF take advantage of that. As a result, I can build an application with thousands and thousands of UI elements in large grids or whatever you can imagine and the computer can actually handle it while simultaneously ripping CD's. Parallel processing is sweet.

Of course, there is one little problem. It is slow to start up a WPF application after a fresh reboot. It's faster after subsequent launches, but on the first launch Windows typically has to start the font cache service because by default it is not configured to start automatically. I know that plays a big part in the slow start up but I'm sure there are other factors. To give you some idea of what I mean by slow, I'd say Data Comparisons Express typically takes around 5-7 seconds to start up after a fresh reboot on the computers I've tested it with. That may not sound like a terribly long time. But when you're a speed freak like me, it's an eternity. Especially considering the entire application fits into a 315 KB installer.

Apparently Microsoft has been working on this and made some big improvements in .NET 3.5 SP1. But it's still not fast enough. I hope they can improve it more, and improve it soon because other than that WPF really is a beautiful thing.