I can use CreateGraphicElements to add lines, points and polygons to my layout and performance is great (creating 100 line graphics using CreateGraphicElements takes 0.753 seconds).
Adding 100 text graphics using the same CreateGraphicElements call and structure takes over 25 seconds - performance that is 30x slower than a non-text, geometric graphic (point, line poly). That's something special and not in a good way 😞
Is there some secret to adding a CIMTextGraphic to a layout where I could get performance similar to adding a CIMLineGraphic, CIMPointGraphic, etc?
Here's the test code that I have been working with:
Layout layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault()?.GetLayout();
GroupElement groupElement1 = LayoutElementFactory.Instance.CreateGroupElement(layout);
CIMElement cimGroupElement = groupElement1.GetDefinition();
cimGroupElement.Name = "Group Element Test - Lines";
groupElement1.SetDefinition(cimGroupElement);
//Creating a GroupElement that only consists of line graphics
var graphics = new List<CIMGraphic>();
var names = new List<string>();
for (int i = 0; i < 100; i++)
{
List<Coordinate2D> lineCoordinates = new List<Coordinate2D> { new Coordinate2D { X = i, Y = 0 }, new Coordinate2D { X = i, Y = 100 } };
Polyline polylineTic = PolylineBuilder.CreatePolyline(lineCoordinates);
CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 1.0, SimpleLineStyle.Solid);
graphics.Add(new CIMLineGraphic() { Line = polylineTic, Symbol = new CIMSymbolReference() { Symbol = lineSym } });
names.Add($"Line{i}");
}
//Following line takes 0.75 seconds to execute
LayoutElementFactory.Instance.CreateGraphicElements(groupElement1, graphics.ToArray(), names.ToArray());
//Creating a GroupElement that only consists of text graphics
GroupElement groupElement2 = LayoutElementFactory.Instance.CreateGroupElement(layout);
CIMElement cimGroupElement2 = groupElement2.GetDefinition();
cimGroupElement2.Name = "Group Element Test - Text";
groupElement2.SetDefinition(cimGroupElement2);
graphics = new List<CIMGraphic>();
names = new List<string>();
for (int i = 0; i < 100; i++)
{
graphics.Add(new CIMTextGraphic() { Shape = new Coordinate2D { X = i, Y = i }, Symbol = new CIMSymbolReference() { Symbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 6, "Arial Narrow", "Regular") }, Text = i.ToString() });
names.Add($"Point{i}");
}
//Following line takes > 25 seconds to execute; same usage as above, only difference is the graphics list now contains CIMTextGraphic objects instead of CIMLineGraphic objects
LayoutElementFactory.Instance.CreateGraphicElements(groupElement2, graphics.ToArray(), names.ToArray());
There is another thread that deals with the degradation of performance when adding elements in multiple nested GroupElements, but in this situation I am using CIMTextGraphic and I am not nesting.