Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Diagram rendering performance issue for nodes (Read 4182 times)
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Diagram rendering performance issue for nodes
Mar 19th, 2010 at 9:54am
Print Post  
Hi,

We need to show two columns with 1024 nodes in each column. and need to show shadow for shape nodes but not for the attached label node. It is taking around 18 seconds. We need to improve this performance.

Let know how we can improve this performance. Is there any way that we can use separate thread or background worker to improve the performance.

It will really be helpful if you provide sample code for this.

We have sent a sample project regarding this issue at your support ID. Please have a look into that.

Thanks,
Bala
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Diagram rendering performance issue for nodes
Reply #1 - Mar 19th, 2010 at 12:10pm
Print Post  
Hi,

It takes 5-6 seconds with the following modifications:

Code
Select All
var now = DateTime.Now;
diagram.ValidityChecks = false;
diagram.BeginInit();
for (int i = 0; i <= 1024; i++)
{
	ShapeNode srcNode = createNode(new Rect(100, 100 + i * 40, nodeWidth, nodeHeight));
	ShapeNode snkNode = createNode(new Rect(400, 100 + i * 40, nodeWidth, nodeHeight));
	DiagramLink link1 = new DiagramLink(diagram, srcNode, snkNode);
	diagram.Links.Add(link1);
}
diagram.EndInit();
diagram.LinkCrossings = LinkCrossings.Cut;
Debug.WriteLine(DateTime.Now - now);
 



where diagram.LinkCrossings is moved from InitDiagram. And the createNode method is refactored to use shared BitmapImage and ShadowEffect objects:

Code
Select All
BitmapImage encoderImage = new BitmapImage(
	new Uri(@"..\..\Encoder.png", UriKind.RelativeOrAbsolute));
Color shadowColor = new Color { ScA = 1, ScB = 0, ScG = 0, ScR = 0 };
DropShadowEffect dropShadow = new DropShadowEffect {
	RenderingBias = RenderingBias.Performance, ShadowDepth = 8 };

private ShapeNode createNode(Rect rect)
{
	var mainNode = new ShapeNode { Bounds = rect };
	diagram.Nodes.Add(mainNode);
	// ...
	mainNode.Image = encoderImage;

	// ...
	var lr = new Rect(mainNode.Bounds.X - mainNode.Bounds.Width, mainNode.Bounds.Y,
		mainNode.Bounds.Width, mainNode.Bounds.Height);
	var lableNode = new ShapeNode { Bounds = lr };
	diagram.Nodes.Add(lableNode);
	lableNode.AttachTo(mainNode, AttachToNode.MiddleLeft);

	// ...
	mainNode.Effect = dropShadow;

	return mainNode;
} 



There was an unnecessary Nodes.Add(mainNode) at the end of the method, now remove. Watch out for adding items two times, especially with ValidityChecks disabled.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Re: Diagram rendering performance issue for nodes
Reply #2 - Mar 23rd, 2010 at 3:02pm
Print Post  
Hi,

Thanks for the code snippet, it improves the performance.

We are having a little issue with this code.

After implementing the suggested changes, the attached label node text are now displaying too far from the main node for the left column.

Earlier the label node text was displayed properly.

We have reproduced this issue in the sample. We are sending the sample, please suggest.

Regards,
Bala
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Diagram rendering performance issue for nodes
Reply #3 - Mar 23rd, 2010 at 3:45pm
Print Post  
Hi,

Try replacing these lines

Code
Select All
lableNode.TextFormat.Alignment = StringAlignment.Far;
lableNode.TextFormat.LineAlignment = StringAlignment.Far;
lableNode.TextFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft; 



with

Code
Select All
lableNode.TextFormat = new StringFormat
{
	Alignment = StringAlignment.Far,
	LineAlignment = StringAlignment.Far
}; 



You should assign a new object, because otherwise the nodes share a common StringFormat instance as default, which is later changed to left-aligned for the second column. This worked before because the ShapeNode(Diagram) constructor clones the format object, however we replaced it with a no-args constructor, which works faster.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Bala
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 156
Joined: Apr 21st, 2009
Re: Diagram rendering performance issue for nodes
Reply #4 - Mar 24th, 2010 at 1:10pm
Print Post  
Hi Stoyan,

Thanks a lot for your suggestion. Now everything is fine.

Thanks,
Bala
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint