Poor performance when a elements programmatically


I have an issue regards performance when adding lots of diagram items, if I have 40,000 lines it takes around 28 seconds to add another 1000 lines, and the time gets longer and longer (30 seconds when going from 44,000 to 45,000).

I have tried using diagram BeginUpdates and EndUpdates but this doesn't seem to have much effect. I also happen to have a diagram navigator control linked to the diagram and this also gets updated even after BeginUpdates is called.

A single CPU core is also being maxxed out whilst doing this. 

Is there any workaround I can do to make this quicker ?

By the way I'm running on a Win 10 PC with I7.


Just to add another point, when the data is saved to a dgr file, and reloaded the reloading and rendering only takes a minute! 

The issue here is probably naming the components. When you insert a new object in the diagram without a name, the component tries to find a unique name, and if it does that to all components, it will eventually iterate through all the existing objects to find a new unique one.

Just make sure you give an unique name to the object before inserting it in diagram (before setting Diagram property) and it should be fast.