none
Is there any to improve performance on Dropping shapes ? RRS feed

  • General discussion

  • Hi

    I do some batch drop that takes about 2 minutes in my VSTO add-in. I do these just before dropping to improve performance:

    VisioApplication.EventsEnabled = 0;
    VisioApplication.ShowChanges = false;
    VisioApplication.DeferRecalc = 1;
    VisioApplication.AutoLayout = false;
    LiveDynamics = false;
    UndoEnabled = false;

    also:  dropmany and setformulas


    Do you have any other advice to improve the performance. Actually right now dropping shapes and setting formulas doesn't take that much in my C# code but Visio do some processes after dropping that takes a long time to finish.

    Thank you in advance

    Danesh


    Tuesday, March 3, 2015 7:06 PM

All replies

  • 1. Where's the line of code that actually does the drop?

    2. Is there an event handler for adding a shape?

    3. Are they your own shapes or standard Visio shapes?

    4. How complicated are the shapes? Are they groups? Are they images?

    5. Do the shapes contain complicated formulae?

    6. Do the shapes contain on drop event handlers?


    Paul Herber, Sandrila Ltd. Engineering and software shapes for Visio
    Sandrila Ltd

    Tuesday, March 3, 2015 7:33 PM
  • Thank you for your response.

    1- I copied some parts of the drop at the bottom of the message. Any way I implemented both drop and dropmany. It doesn't make that much change.

    2- I detach all the event handlers before drop and attach them after drop. But SOME TIMES I see that some events fire on drop. (maybe its because of asynchronous call of interop) or for example QUEUEMARKEREVENTs fires after first move. Anyway when I completely disabled them in the test environment I just save few seconds.

    3- I have my own shapes. They are not Visio standard shapes.

    4- They are groups. few of them have image in it. but they are small symbols.

    5- They don't have complicated formula.

    6- I detached shapeAdded , Cellchange and other events before starting drop.

    A wired thing is: When I drop all of the shapes in 5 different steps, its so faster than dropping all of them together.

    I mean time of dropping 50 shapes is much more that 5 times of dropping 10 shapes. (I'm talking about same shapes in both situations.)

    Some parts of my code:

    _visioPage.DropManyU(ShapesToDrop.Values.ToList().Select(v => v.Master).ToArray(), _xy.ToArray(), out _visioShapeIds);
           private void SetFormulaS(Shape shape, ShapeToDrop shapeToDrop)
            {
                var sheetSectionRowColumn = new short[shapeToDrop.Formulas.Count * 3];
                var formulaArray = new object[shapeToDrop.Formulas.Count];
                int i = 0;
                foreach (var cellInfo in shapeToDrop.Formulas)
                {
                    var cellAddress = VisioCellUtil.GetCellAddress(shape, cellInfo.CellName);
                    sheetSectionRowColumn[(i * 3) + 0] = cellAddress.Section;
                    sheetSectionRowColumn[(i * 3) + 1] = cellAddress.Row;
                    sheetSectionRowColumn[(i * 3) + 2] = cellAddress.Cell;
                    string formulaStr = cellInfo.Formula;
                    formulaStr = ReplaceResourceId(formulaStr, shape);
                    formulaArray[i] = formulaStr;
                    i++;
                }
                short flags = (short)(VisGetSetArgs.visSetBlastGuards | VisGetSetArgs.visSetUniversalSyntax);
                shape.SetFormulas(sheetSectionRowColumn, formulaArray, flags);
    
            }


            private void SetResultS(Shape shape, ShapeToDrop shapeToDrop)
            {
    
                var sheetSectionRowColumn = new short[shapeToDrop.Results.Count * 3];
                var resultArray = new object[shapeToDrop.Results.Count];
                var unitCodeArray = new object[shapeToDrop.Results.Count];
                int i = 0;
                foreach (var cellInfo in shapeToDrop.Results)
                {
                    var cellAddress = VisioCellUtil.GetCellAddress(shape, cellInfo.CellName);
                    sheetSectionRowColumn[(i * 3) + 0] = cellAddress.Section;
                    sheetSectionRowColumn[(i * 3) + 1] = cellAddress.Row;
                    sheetSectionRowColumn[(i * 3) + 2] = cellAddress.Cell;
                    resultArray[i] = cellInfo.Result;
                    unitCodeArray[i] = (short)VisUnitCodes.visInches;
                    i++;
                }
                short flags = (short)(VisGetSetArgs.visSetBlastGuards);
                shape.SetResults(sheetSectionRowColumn, unitCodeArray, resultArray, flags);
    
            }



       And when I drop one by one (that is not that much different change in final time)

                Shape newShape = VisioPage.Drop(master, shapePosition.X, shapePosition.Y);
                
    
                if (stencilId != "Comment")
                {
                    if (!string.IsNullOrWhiteSpace((string)sourceShape.properties.name))
                    {
                        newShape.Text = sourceShape.properties.name;
                    }
                    newShape.Ext_GetCell("Width").ResultForce[VisUnitCodes.visInches] = shapePosition.Width;
                    newShape.Ext_GetCell("Height").ResultForce[VisUnitCodes.visInches] = shapePosition.Height;
                }
                if (stencilId == "Annotation")
                {
                    if (!string.IsNullOrWhiteSpace((string)sourceShape.properties.text))
                    {
                        newShape.Text = sourceShape.properties.text;
                    } 
                }

    the Ext_GetCell method is an extension method, I used that to find the cell SRC (Section,Row,Cell) ids based on a dictionary and work with the cell in that way to improve performance.

    Tuesday, March 3, 2015 8:05 PM
  • Is there any way to temporary disable all of the QUEUEMARKEREVENTs ?
    Tuesday, March 3, 2015 8:30 PM
  • I have no idea how much time connecting and disconnecting events will take, not insignificant I'd say. Those foreach loops: how many times are they looping?

    Assuming you are using Visual Studio ... how big is the binary file? Is it a debug version? Is there a huge debug symbol file?


    Paul Herber, Sandrila Ltd. Engineering and software shapes for Visio
    Sandrila Ltd

    Tuesday, March 3, 2015 9:14 PM
  • Yes, I'm using Visual Studio.

    Add-on binary file is 2,600 KB. But including all of references and Visio Templates and external files is 170 MG.

    The visio file, when I drop shapes in an empty template and save it as a vsdx file it's 818 KB.

    The sample that I'm talking about contains about 600 shapes including connectors. (this is the number of main loop)

    We test add-on both with debug and release builds.


    Tuesday, March 3, 2015 9:26 PM
  • Hi,

    This is the forum to discuss questions and feedback for Microsoft Visio, I'll move your question to the MSDN forum for Visio Dev

    http://social.msdn.microsoft.com/Forums/en-US/home?forum=officegeneral&filter=alltypes&sort=lastpostdesc

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    George Zhao
    TechNet Community Support


    It's recommended to download and install Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office programs.

    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.
    Wednesday, March 4, 2015 9:44 AM
  • Hi,

    This is the forum to discuss questions and feedback for Microsoft Visio, I'll move your question to the MSDN forum for Visio Dev

    http://social.msdn.microsoft.com/Forums/en-US/home?forum=officegeneral&filter=alltypes&sort=lastpostdesc

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    George Zhao
    TechNet Community Support


    It's recommended to download and install Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office programs.

    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    George, this is a Visio question. I was in the middle of trying to help this person.


    Paul Herber, Sandrila Ltd. Engineering and software shapes for Visio
    Sandrila Ltd

    Wednesday, March 4, 2015 10:12 AM
  • Hi Paul,

    Thanks for your effort. Let me explain it: We are not supporting the Develop issue of Visio in TechNet forum. I hope some experts, like you to help our customer better. Thus, I move the thread to MSDN forum, the poster also can find the thread with his profile.

    Regards,

    George Zhao
    TechNet Community Support


    It's recommended to download and install Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office programs.

    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Friday, March 6, 2015 3:27 AM
  • As an observation from the side, me experience with dropping multiple shapes is that most of the processing time is taken after the shapes have been delivered and while I am programmatically updating shape data, etc. I never attempted to discover whether the delay was actually in the update, or in the finding of the new shape on the page in preparation to the update.

    al


    Al Edlund Visio MVP

    Friday, March 6, 2015 7:10 PM
  • George,

    Since the msdn and TechNet forums are mirrors of each other, moving a post is a waste of time.

    al


    Al Edlund Visio MVP

    Friday, March 6, 2015 7:11 PM
  • Hi Daneshk,

    >>>> Actually right now dropping shapes and setting formulas doesn't take that much in my C# code but Visio do some processes after dropping that takes a long time to finish.<<

    The Visio object model will be used to manipulate Visio in code (like sending a command to code). But Visio need the time to process this operations (like moving a batch of shapes).

    I suggest to test the performance manually to identify the bottleneck of the performance (in the code or in the Visio). If the limitation is from the Visio side, I'm afraid we can hardly improve it from the code side.

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 10, 2015 11:41 AM
    Moderator
  • Hi Regards & Fei

    I used Visual Studio Profiler and JerBrains dotTrace to find out the root cause. I think it's in Visio side.

    Anyway thank you so much for your response.

    Danesh

    Tuesday, March 10, 2015 1:27 PM