Use AL TextBuilder for repeated text mutation
AL TextBuilder is a reference type intended for modifying text without creating a new Text value for each change. Microsoft documents it as the performance-oriented AL primitive for concatenating many strings, including loop-built output.
- microsoftlayer
- performancedomain
- 0examples
- 1pull request
Rule on GitHub · microsoft layer · performance · BC all · tier official · derived
Description
AL TextBuilder is a reference type intended for modifying text without creating a new Text value for each change. Microsoft documents it as the performance-oriented AL primitive for concatenating many strings, including loop-built output. Append and AppendLine build the value, and ToText returns the completed text.
Best Practice
When a loop repeatedly appends fragments to one result, use a TextBuilder local and convert once after the loop. Keep ordinary Text expressions for a fixed, small number of fragments; this rule is about repeated mutation, not every concatenation.
Anti Pattern
Building an unbounded export or message with Result += Fragment on every iteration when AL’s TextBuilder directly represents the operation.
Names
- TextBuilder.AppendLine([Text]) Method (names AppendLine)
Changed by
- #94 Correct performance knowledge guidance, 2026-07-14
From microsoft/BCQuality at a4593a1, MIT License, Copyright (c) 2026 Microsoft Corporation (license).