Performance issues with InsertShape when WrapType is Inline

I have been working on a document generation method and was getting reports that after switching from Xamarin to MAUI, we started to experience the document takes sometimes twice as long as usual to generate.

I was tasked with deep diving into it to find what was going on and I found that there is a call that takes over a second to complete it is almost a single point of bottleneck besides the save call.

[Instrumentation] BuildAcknowledgeTable START: 2025-09-29T19:53:38.4298440-04:00
[Instrumentation] BuildAcknowledgeTable StartTable: 0 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable Set font bold/size: 0 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable First cell setup (non-CA): 0 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable WritelnSafe blanks 1: 0 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable InsertShape initialsLine1: 1064 ms (+1064 ms)
[Instrumentation] BuildAcknowledgeTable WritelnSafe blank 2: 1064 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable WriteSafe General_Initials 1: 1064 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable Second cell setup (non-CA): 1064 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable Write AVL acknowledge text and hyperlinks: 1065 ms (+1 ms)
[Instrumentation] BuildAcknowledgeTable WriteSafe period 1: 1065 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable EndRow 1: 1065 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable First cell setup (main block): 1065 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable Set font bold 2: 1065 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable WritelnSafe blanks 2: 1066 ms (+1 ms)
[Instrumentation] BuildAcknowledgeTable InsertShape initialsLine2: 1066 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable WritelnSafe blank 3: 1066 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable WriteSafe General_Initials 2: 1066 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable Second cell setup (main block): 1066 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable Set acknowledgeText and urlText for AVL: 1067 ms (+1 ms)
[Instrumentation] BuildAcknowledgeTable WriteSafe acknowledgeText and hyperlink: 1067 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable EndRow 2: 1067 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable EndTable: 1067 ms (+0 ms)
[Instrumentation] BuildAcknowledgeTable END: 2025-09-29T19:53:39.4974810-04:00 | Elapsed: 1067 ms

The InsertShape call that is causing this is:

var initialsLine1 = builder.InsertShape(ShapeType.Line, RelativeHorizontalPosition.Character, 0, RelativeVerticalPosition.Paragraph, 0, 20, 0, WrapType.Inline);

I can’t understand why it would have such a big performance hit.

I can provide any additional information needed here, but I was curious if there is any pitfalls that I may need to consider if if this may be a bug with the DocumentBuilder

@DarnellEightbot

The performance issue you’re experiencing with the InsertShape method when using WrapType.Inline may be due to the way inline shapes are processed in the document. Inline shapes can lead to performance bottlenecks, particularly in complex documents or when inserting multiple shapes in a loop.

Here are several suggestions to potentially improve performance:

  1. Batch Insertions: If you are inserting multiple shapes, consider batching the insertions or reducing the total number of shapes if feasible.

  2. Use Floating Shapes: If the layout permits, try using WrapType.Floating instead of WrapType.Inline. Floating shapes can sometimes be more efficient in terms of rendering.

  3. Profile Your Code: Utilize profiling tools to identify other areas in your code that may be contributing to the slowdown.

  4. Check for Updates: Ensure you are using the latest version of the Aspose library, as performance improvements and bug fixes are regularly released.

  5. Simplify Shapes: If the shapes being inserted are complex, consider simplifying them or reducing their properties (such as line thickness).

If the issue persists, consider reaching out to Aspose support or checking their forums for similar issues reported by other users.