Please wait
Talk to Expert
Microsoft Dynamics Business central, Microsoft Dynamics NAV

“Optimizing AL Extensions: The Benefits of Using TextBuilder Over Text”

using TextBuilder Data Type over Text.

Optimizing AL extensions is crucial for enhancing performance and efficiency. One significant optimization technique involves using the TextBuilder data type instead of the traditional Text type for string operations. TextBuilder is specifically designed for scenarios involving frequent string manipulations, such as concatenations and modifications, offering a more efficient and performance-oriented approach.

Unlike the Text type, which can be inefficient due to repeated allocations and copying, TextBuilder maintains a dynamic buffer that reduces overhead and enhances processing speed. By leveraging TextBuilder, developers can create more responsive and performant extensions, leading to improved user experiences and reduced resource consumption.

So before we go for benefits let’s see the description of both.

TextBuilder Data Type

1. TextBuilder Data Type
• The TextBuilder data type is a reference type, which holds a pointer elsewhere in memory. For performance reasons, we recommend you use it when you want to modify a string without creating a new object. For example, using TextBuilder data type can boost performance when concatenating many strings together in a loop.
• You may can check more about TextBuilder Data Type from this link


Text Data Type

2. Text Data Type
• The Text Data Type is a value type, such that every time you use a method on it, you create a new string object in memory. This requires a new allocation of space. In situations where you need to perform repeated modifications to a string, the overhead associated with creating a Text Data Type can be costly.
• You may can refer this link to Check more about functions of Text Data Type

Step 1

Here below we have created two separate codeunits to configure both codeunits into Job Queues. And these codeunits are doing a simple job of concatenation of a string but 100 times which is mentioned in the For Loop.


Step 2

And here is the results when we both Codeunits got executed. Here we cannot see a notable difference. Hence we will increase loop iteration no to 2,00,000 times and then we will see the results.


Step 3

As discussed above we have updated the No of iteration here.


Step 4

And here are the results.
Concat with TextBuilder codeunit took time of 300 milliseconds where as Concat with Text took time of 6 Minutes and 17 Seconds.


Thank you for investing your time to read our blog! We’re passionate about sharing valuable insights to help you navigate the world of Business Central.

If you’re curious about how we can assist you in reaching your goals, don’t hesitate to get in touch. Our dedicated team is ready to provide support every step of the way.

Let’s turn your vision into reality together!