Solution Performance Tip 1 – GetFormulas and SetFormulas


One of the most frequent questions I get from partners and other readers of this blog is how to improve the performance of their solution. Usually the first step is to point them to these five performance tips, but I thought it would be interesting to quantify just how much of a difference some of these tips actually make in the real world.

It just so happens that the Visio SDK includes some relevant samples in the "Visio Code Samples Library" that we can use to evaluate this. To test this, I used (slightly modified) the "Get Many & Set Many Formulas" code example in the "Shapes" section. I ran this using two of the main ways of automating Visio using managed code (specifically C# in this case): VSTO and instantiating Visio from an external executable. The example drops shapes then sets and retrieves formulas in two different ways: one by one and using GetFormulas and SetFormulas. Here are the results of running the tests (average of 10 runs each):

VSTO

 

100 Shapes

1000 Shapes

Individual Get

0.11 sec

0.36

GetFormulas

0.01 sec

0.11

Individual Set

0.31 sec

0.63

SetFormulas

0.01 sec

0.20

External Executable

 

100 Shapes

1000 Shapes

Individual Get

0.45 sec

4.3 sec

GetFormulas

0.03 sec

1.9 sec

Individual Set

0.17 sec

14.3 sec

SetFormulas

0.14 sec

0.5 sec

As you can see, moving to the GetFormulas/SetFormulas style (which minimizes the number of objects that are passed back and forth) has huge performance implications. This is particularly evident when using an external executable which instantiates Visio, since this now means that your calls to Visio must cross process boundaries, which is expensive (I'll cover this topic more fully in a future post).

Using GetFormulas/SetFormulas is a little trickier than just doing things one at a time, but is usually well worth the effort. The samples in the SDK are a great way to get started.