Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic SVG performance slowdown (Read 919 times)
nullable
Junior Member
**
Offline


I Love MindFusion!

Posts: 86
Joined: Aug 25th, 2022
SVG performance slowdown
Jan 18th, 2023 at 4:34am
Print Post  
Hi, we have a huge performance drop with large svg files (example in attachments). I just want to clarify, is it because vector-based images store geometric points and data and cause rendering slowdown as long as it updates. Сan we possibly do something with this?
  

source.svg ( 575 KB | 34 Downloads )
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: SVG performance slowdown
Reply #1 - Jan 18th, 2023 at 7:46am
Print Post  
Hi,

SvgNode was intended for showing icons in the diagram and doesn't do any caching of render results at this time. A large SVG drawing would cause multiple calls to RenderContext's draw-primitive methods when node's coordinates change, and will generally create large WPF visual tree slowing down screen refreshes.

You could try caching SVG renderings yourself by creating RenderTargetBitmap from SvgNode, and then only drawing the bitmap using a transparent ShapeNode or a custom type:

Code
Select All
var bounds = new Rect(0, 0, 400, 200);

var svgRenderer = new SvgNode
{
	Content = SvgContent.FromFile("source.svg"),
	Bounds = bounds,
	Transparent = true // hide shape geometry
};

var cache = new RenderTargetBitmap(
	400, 200, 96, 96, PixelFormats.Default);
var visual = new DrawingVisual();
var context = visual.RenderOpen();
svgRenderer.DrawLocal(context, diagram.PrintOptions);
context.Close();
cache.Render(visual);

var node = new ShapeNode
{
	Image = cache,
	Bounds = bounds,
	Transparent = true // hide shape geometry
};
diagram.Nodes.Add(node);

// todo: refresh cache when node resizes, but maybe only
// when scale changes substantially to not redraw very often 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: SVG performance slowdown
Reply #2 - Jan 18th, 2023 at 7:57am
Print Post  
with that approach you'd need to switch temporarily back to SvgNode for the svg-to-svg exports you were showing in older thread, if you want vector graphics preserved.
  
Back to top
 
IP Logged
 
nullable
Junior Member
**
Offline


I Love MindFusion!

Posts: 86
Joined: Aug 25th, 2022
Re: SVG performance slowdown
Reply #3 - Jan 18th, 2023 at 9:16am
Print Post  
Thank you!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint