Performance Optimisation: Making AL Code Work Smarter, Not Harder


As Business Central environments grow, performance becomes increasingly important.

Working with thousands — or even millions — of Customer Ledger Entries, Vendor Ledger Entries or Detailed Ledger Entries can introduce significant performance challenges.

A report or processing routine that works perfectly with a small dataset might become a bottleneck when dealing with millions of records.

So, how do we optimise AL code for large datasets?

Some practical AL performance techniques worth considering:

1. SetLoadFields()

Only load the fields your code actually needs. Avoid retrieving unnecessary data from SQL.

2. SetCurrentKey()

Use appropriate keys to help SQL Server retrieve records efficiently, particularly when working with large ledger tables.

3. SetRange() and SetFilter()

Apply filters as early as possible to reduce the number of records processed.

4. Avoid unnecessary CalcFields()

Be selective with FlowField calculations. Use SetAutoCalcFields() where appropriate and avoid repeatedly calculating values inside large loops.

5. Minimise database calls

Avoid unnecessary Get(), FindFirst() and CalcSums() operations inside loops. Consider restructuring the logic to reduce database round trips.

6. Choose the right data structure

Temporary tables and in-memory processing can help reduce database operations when aggregating or manipulating large datasets.

The real objective

  • Faster report execution.

  • Reduced database load.

  • Better user experience.

  • More scalable Business Central solutions.

Remember: Performance optimisation isn't about writing fewer lines of AL code. It's about writing code that makes fewer unnecessary database operations and processes data intelligently.

#Dynamics365BusinessCentral #BusinessCentral #ALDevelopment #MicrosoftDynamics365 #ERP #PerformanceOptimisation #SaaS #MicrosoftPartner

Comments