The great thing about trying to improve performance is the ease with which you can pick off the low hanging fruit to make a meaningful difference.
This was the first time I had run the library through a performance tool so I was hoping that there would be one or two simple changes I could make to boost the library. Not that anyone had complained about the speed of the library.
Sadly I do not have the Team System version of Visual Studio aimed at developers which comes with some nice tools including performance analysis. Being part of the ISV Empower program means I miss out of those goodies as I only get the professional edition.
So instead I had a look around for something cheap but functional. I decided on the ANTS Profiler because it is easy to use and gives enough detail to get going.
After a little investigation it became obvious there was an inefficiency that could be removed to make a big impact. Most of the toolkit controls can have transparency in either the border or background. To allow for this the controls always draw the parent container before the control itself. This ensures that any part of the control that is transparent will show the correct background.
Now if the control does not happen to have any transparent areas then drawing the background is very wasteful. In fact it can be horribly wasteful. You might have a button that sits inside a panel that is in a header group that is on a split container panel. Drawing the button involves asking the parent panel to draw, which in turn then asks for the header group to draw and so forth up the chain.
So I have added some logic that decides if the control has any transparent element and will only ask for the parent background to be drawn when it is required. For my small test application this reduced the execution time by half. Considering this test app was small and so had relatively few layers of controls it means a real world application is likely to benefit even more.
By default the two built in palettes provided with the toolkit have no transparent areas on any of the controls, so they both get maximum benefit from the change. The custom palettes provided in the Palettes installation directory all have rounded edges and so will not benefit to the same extent.
This is a trick worth bearing in mind if you want to improve the drawing performance of the library, make sure your custom palette does not make too much use of transparency on those controls you use most often.