Visio Insights
The official blog of the Microsoft Visio product team

Master Benefits

Master Benefits

  • Comments 0

One of the things we'd like to accomplish with this blog is to highlight some performance optimizations that shape designers and developers should consider adopting as best practices.  Unfortunately designing highly efficient shapes and solutions is a bit of a black art in Visio.  Today we will look at the fundamental issue of using masters.

Master shapes and instance shapes are described in this post.  A master shape allows Visio to store a single copy of a shape definition and only manage the information that is different for each instance of a shape.  For many shapes, only the Shape Transform section of the Shapesheet is specific (or "local" as we call it) to each instance.  That section contains the PinX and PinY coordinates for the shape's location on the page.  As you modify a shape on the page, more Shapesheet cells take on custom values rather than inherit their values from the master shape.  Thus Visio requires more memory to manage this information.

A masterless shape, such as a line or rectangle drawn with the drawing tools is essentially 100% local values.  That means Visio must store the complete set of Shapesheet properties for each and every shape on the page.  Let's compare Visio's performance when working with instances of masters versus masterless shapes.  We'll just create a master that consists of a plain rectangle for the master shape.  We'll draw a plain rectangle using the drawing tools for a masterless shape.  Then to get a better reading on the incremental costs of working with these shapes, we duplicate each 100 times.  The numbers below are based on some tests done with Visio 2003.

When comparing memory consumption, the masterless rectangle requires about 11,700 bytes per shape.  The master instance rectangle requires about 3,600 bytes per shape.  The difference gets larger if you apply formatting to the rectangles.  The masterless rectangle with custom line, fill and text colors set requires about 33,000 bytes per shape.  The master instance rectangle only uses 6,300 bytes per shape.  Note that Undo was enabled for this, which would exaggerate the numbers a bit.

These differences also impact the file size of the Visio document.  A blank Visio document uses about 18 kilobytes of space.  A document with 100 masterless rectangles uses about 52 kilobytes.  The 100 master instance rectangles use about 45 kilobytes.  Thus when you subtract out the document overhead, masterless requires 26% more space.

Finally, we can look at the time it takes Visio to create 100 shapes on the page.  This was measured with Undo disabled and a little automation script to drop the shapes.  100 masterless rectangles were created in about 95 milliseconds.  100 master instance rectangles were created in about 47 milliseconds.  Much of the performance differences relates to the extra memory footprint required for the masterless rectangles.

Hopefully this gets you thinking about the efficiency of your own content and code.  Do you generate large diagrams by drawing lots of lines and rectangles?  You should think about masters.  Do you work with masters but heavily customize the shape instances once they are on the page?  Perhaps you can consolidate the customizations into a few masters that can be instanced.  Or perhaps you can place many of the customizations into a Visio style and apply that to your shape instances.  Do a little measurement with Windows Task Manager yourself to understand what the per shape memory costs are.

We'll take a look at additional performance optimizations in some future posts.

 

 

Leave a Comment
  • Please add 7 and 4 and type the answer here:
  • Post