Mathias Brandewinder on .NET, VSTO and Excel development, and quantitative analysis.
by Mathias 16. April 2009 18:55

Now that I have the core functionality in for the “Blue Lobster” project, it’s time for some optimization. Part of the application revolves in displaying the contents of an Excel worksheet, which I implemented populating a Grid control. One issue which was bugging me was that displaying large amounts of data was somewhat slow. My “large” test Excel worksheet is roughly 200 rows by 200 columns, which doesn’t seem like much, until you realize that these are 40,000 cells. Each of these cells was initially represented as a CellView, a simple WPF home-made control.

My initial thought was that the source of the problem was in multiple resizing of UI elements, but when I ran the profiler, it turned out that most of the time was actually spent instantiating each instance of the CellView control. I am still not sure what made my control so costly to instantiate, but I replaced it by a standard CheckBox, using Templates and Triggers to adapt its appearance, and voila! The time went down from 1 minute 15 seconds to under 30 seconds.

The moral of the story:

1) When optimizing, don’t trust your instinct, trust the profiler.

2) Instantiating a WPF user-defined control is not necessarily lightweight.

3) Before creating your own, try to use an existing control and modify its look through templates.

Comments

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Comments

Comment RSS