Skip to content

AL Performance

File al-performance.instructions.md
Applies to **/*.al
Activation Always active
Role Optimization patterns

Purpose

Performance optimization guidelines for writing scalable AL code. Focuses on data retrieval efficiency, query optimization, and resource-conscious patterns.

Key rules

Rule What it does
Early filtering Apply SetRange/SetFilter before FindSet, never filter in-loop
SetLoadFields Load only needed fields; place before Get/Find operations
Temporary tables Use for intermediate processing to avoid database round-trips
Set-based operations Prefer ModifyAll, DeleteAll over record-by-record loops
Avoid unnecessary loops Use Count, IsEmpty instead of iterating

Pattern: Early filtering

// Good — filter before processing
Customer.SetRange(City, CityFilter);
Customer.SetRange(Blocked, Customer.Blocked::" ");
if Customer.FindSet() then
  repeat
    // Process only matching records
  until Customer.Next() = 0;

Pattern: SetLoadFields

// Good — load only needed fields
Item.SetRange("Third Party Item Exists", false);
Item.SetLoadFields("Item Category Code");
Item.FindFirst();

Avoid

Filtering inside loops, loading all fields when only one is needed, or using SetLoadFields after the Find operation.


Source: instructions/al-performance.instructions.md