Hi,
I got a weird performance issue with the System.Windows.Shapes.Path class.
I have a loop creating about 40,000 paths into a Canvas. There are one or two handfuls of different Brushes used for the objects.
When I create a new SolidColorBrush for each iteration, the loop takes about 3.5 seconds:
Brush brStroke = null; for (uint index = 0; index < count; index++) { System.Windows.Shapes.Path path = new System.Windows.Shapes.Path(); path.Data = GetPathData(); brStroke = new SolidColorBrush(GetColor(index)); path.Stroke = brStroke; path.StrokeThickness = thickness; canvas.Children.Add(path); }
I thought I could speed this up a bit by creating a dictionary for the brushes and cache them. But this version of the loop takes 90 seconds!
Dictionary<ushort, Brush> brushes = new Dictionary<ushort,Brush>(); Brush brStroke = null; for (uint index = 0; index < count; index++) { System.Windows.Shapes.Path path = new System.Windows.Shapes.Path(); path.Data = GetPathData(); ushort gt = GetColorTableIndex(index); if (brushes.ContainsKey(gt)) brStroke = brushes[gt]; else { brStroke = new SolidColorBrush(GetColor(index)); brushes.Add(gt, brStroke); } path.Stroke = brStroke; path.StrokeThickness = thickness; canvas.Children.Add(path); }
Why that?
Does anybody have an idea?
Thanks,
Thomas