cart: empty [ Login ]

Symbol attributes / Text rendering performance

1 
Chris Smith
2/15/2022 11:40 AM
Hi Wout and co, Given the improvement we saw with the font thing, I thought I should post the other two "hot" areas we see in CadLib and see if there's anything that can be done to improve those. The first is DxfInsert.AddAttribute which is currently taking about 30 seconds out of 150 seconds in our test cases - there are 29 calls to this (so approx 1 second per call). Our code to call this looks like:
C# Code:
var dxfAttributeDefinitions = dxfBlock.GetAttributeDefinitions().ToList(); if (dxfAttributeDefinitions.Any()) { bool autoFlip = (vectorSymbol.Style.Symbol.AutoFlip ?? false) && ((rotation > HalfPi && rotation < OneAndAHalfPi) || (rotation < -HalfPi && rotation > -OneAndAHalfPi)); foreach (DxfAttributeDefinition dxfAttributeDefinition in dxfAttributeDefinitions.Where(x => x.Invisible == false)) { try { DxfAttribute attr = null; if (dxfAttributeDefinition.Constant) { attr = insert.AddAttribute(dxfAttributeDefinition, dxfAttributeDefinition.Text); } else { var modelAttribute = vectorSymbol.Attributes.FirstOrDefault(att => att.Tag == dxfAttributeDefinition.TagString); if (modelAttribute != null) { attr = insert.AddAttribute(dxfAttributeDefinition, modelAttribute.Value); if (modelAttribute.Color != null) { attr.Color = EntityColor.CreateFromColorIndex((short)modelAttribute.Color.Value); } if (modelAttribute.Layer != null) { attr.Layer = this.GetLayer(context.DxfModel, modelAttribute.Layer); } if (modelAttribute.Height != null) { attr.Height = modelAttribute.Height.Value; } if (modelAttribute.Position != null) { attr.Rotation = modelAttribute.Position.Rotation; } } } if (autoFlip && attr != null) { attr.IsUpsideDown = !attr.IsUpsideDown; attr.IsBackwards = !attr.IsBackwards; } } catch (Exception e) { // Logging } } }
And the second is around rendering text / mtext within CreateBitmap which is taking about 34 seconds / 18 seconds respectively in the same 150 overall seconds - there are 38 Texts and 49 MTexts in the sample drawings. Not sure what code would be helpful to show here? See images for profiler breakdown. Happy to email you some sample DWGs if that would help? Cheers, Chris
addattr.png
textmtext.png
Wout
2/15/2022 11:58 AM
Hi Chris, The text rendering itself I probably can't get any faster, but the AddAttribute elapsed time of 1 second sounds excessive, I'd expect it to be milliseconds. Internally it does layout/render (to get the text bounds) the attribute text because of alignment, so it's not a super cheap operation, but I wouldn't think 1 second. If you use left/baseline alignment on the text the code won't even try to align the text, and it skips the expensive layout and alignment call. On any other alignment, it will have to calculate the text bounds to layout the text properly. You can send me a file and a test program to try it out. - Wout
Chris Smith
2/16/2022 9:21 AM
Hi Wout, I've emailed you 4 sample DWG files that are indicative of the more complex type of graphics we would render. They're only a few hundred entities each so generally not too much but we'd be rendering a lot of these small drawings very quickly. Re the text rendering - fair enough - the only thing that seemed odd there was that the Text objects (which I assume are actually the block reference attributes) took quite a bit longer to render than the MText even tho there was more MText. I will say that typically our cusotomers' block attributes are center aligned whereas their MText might be more likely to be left aligned. Re the FixAlignmentPoints call, is there any possibility of caching something about the font or etc which might speed that up? Also, and maybe this is a bit related to the GDI+ error I mentioned elsewhere, but I'm wondering if CadLib will internally ignore features that are entirely outside the render viewport? I can see we've put a bunch of features that are actually outside the area we're going to render in the drawing, so maybe we could filter these out again before we call CreateBitmap. Not sure if its going to be faster to calculate their bounds or just to render them tho... Cheers, Chris
Chris Smith
2/16/2022 10:57 AM
So I tried using the BoundsCalculator to work out if symbols were within the viewport and that was very expensive so don't do that 🙂 Will see if we can reduce the amount of graphics some other way.
Wout
2/16/2022 12:20 PM
Hi, Can you create a Console application to recreate the adding of attributes scenario? I can't compile the code above. - Wout
Chris Smith
2/16/2022 12:24 PM
Hi Wout, I should be able to - I'll have to look at it tomorrow tho. Cheers, Chris
1