Performance issue

Hi Jake,

There is a performance issue in my project.The scenario is:
We are using Go view canvas for rendering drawing objects. For this we are not adding the shapes(GoDrawing, GoStroke etc.) directly on the canvas, but we are first making a GoGroup object, adding this GoGroup object on the canvas and adding the shapes in the GoGroup, so that each and every shape which is on GoView canvas is part of some GoGroup.Now a scenario has come where I have to add close to 75000 objects to GoGroup, this is where the issue comes, my application is taking 10-12 min. even more to draw and show the diagrams.I made a small application and tried adding 75000 GoDrawing objects directly on the canvas and adding a GoGroup object on the go view canvas and then adding these 75000 GoDrawing objects to the GoGroup. The time taken for both operations are 0.9842049 sec. and 8min.and51.5331352 secs respectively. Can you please explain this behaviour for the second case?
The code snippet is attached below:
Adding GoDrawing Shapes directly to Go View canvas(takes 0.9842049 sec. ):
for (int i = 0; i < 75000; i++)
{
GoDrawing gddraw = new GoDrawing(); gddraw.StartAt(0, 10); gddraw.LineTo(10, 20); goView1.Document.Add(gddraw); }
Adding GoGroup to canvas and then adding GoDrawing to GoGroup(takes 8min.and51.5331352 secs):
GoGroup pGoGroup = new GoGroup(); goView1.Document.Add(pGoGroup); for (int i = 0; i < 75000; i++) { GoDrawing gddraw = new GoDrawing(); gddraw.StartAt(0, 10); gddraw.LineTo(10, 20); pGoGroup.Add(gddraw); }

How long does it take if you move adding the Group to the Document after the addition of all the GoDrawings?

It takes 7 min and 47 secs for the second code snippet to get executed.It is an improvement of 1 min. but still there is a difference of approx. 8 min. when we directly add the shapes in GoView canvas and when we add the shapes in Gogroup and then add Gogroup to the Goview canvas.

So the problem stands still.

OK. GoGroup has some code in it to detect mistakes in the user code, and that slows things down a bit. But the big time here is going to computing the Bounds each time an object is added… and that gets slower and slower as you add tens of thousands of objects.



But… there’s a pretty simple workaround that disables most of the work until the end.





[Serializable]

public class FastGoGroup : GoGroup {



protected override RectangleF ComputeBounds() {

if (!Initializing) {

return base.ComputeBounds();

}

else return new RectangleF(this.Location, this.Size);

}

}





then:





FastGoGroup pGoGroup = new FastGoGroup();

pGoGroup.Initializing = true;



… add all your objects



pGoGroup.Initializing = false;

this.goView1.Document.Add(pGoGroup);





I can add the 75K GoDrawings in 0.624 seconds. and that’s on a 3 year old laptop.

Now… that doesn’t mean adding 75000 objects to a GoGroup is a great thing to do… we may want to have an email conversation on the design tradeoffs you are making that led you into this problem in the first place.

Hi Jake,

I tried using your override method but it has got some side effects. I also have UI events attached to my go view, which are not geting raised now like ObjectEnterLeave or any selection event.
Thanks,
Vinayak
P.S.: give me your mail id so that we can have discussion on your last post.

The Bounds of the group may not be right… add this line:





pGoGroup.Initializing = false;

RectangleF b = pGoGroup.Bounds; // new



to force the computing of the bounding box.



send mail to “godiagram”.

Hi Jake,

It did not help.The problem stands still, I am still not getting any events.
Thanks,
Vinayak

Check “b” to see if it looks right after the call to Bounds.

Hi Jake,

Sorry for late reply.
I checked and found that b has incorrect values after the call to bounds.
Thanks and Regards,
Vinayak

do this then: (sets InvalidBounds)



[Serializable]

public class FastGoGroup : GoGroup {



protected override RectangleF ComputeBounds() {

if (!Initializing) {

return base.ComputeBounds();

}

else {

this.InvalidBounds = true;

return new RectangleF(this.Location, this.Size);

}

}

}

Hi Jake,

This code snippet did it.But unfortunately have 1 more problem:
1. When my application is not in focus and I do an Alt-Tab to bring my app. to view, then the Go View takes significant amount of time to repaint.around 4-6 secs(This time is taken manually and can vary from m/c to m/c.)
2. If I try to zoom the area which contains 75K Go Shapes then also it takes significant time. But if I try to zoom any other area which does not have 75K shapes than it takes very less time.
Can you please tell why it is taking such a long time to repaint?
Thanks and Regards,
Vinayak

Well, you’ve got a lot of objects. And you never took me up on that offer to have an offline discussion about your application design.

Hi Jake,


I have sent a mail.


Thanks,
Vin