Prefer a Dictionary over a temporary table for pure lookups
An AL Dictionary directly models an unordered unique key-to-value collection. A temporary table models records and supports keys, filters, validation, and ordered iteration in Business Central Server memory.
- microsoftlayer
- performancedomain
- 0examples
- 1pull request
Rule on GitHub · microsoft layer · performance · BC all · tier official · derived
Description
An AL Dictionary directly models an unordered unique key-to-value collection. A temporary table models records and supports keys, filters, validation, and ordered iteration in Business Central Server memory. For a pure lookup map, the dictionary avoids repeatedly configuring and searching a temporary record and makes the intended access pattern explicit.
Best Practice
Use Dictionary of [Key, Value] when the operation is add-or-replace, contains-key, and get-value by one supported key type. Use a temporary table when the value is a record, or when the code needs filters, ordered iteration, multiple fields, multiple keys, or table behavior. Both structures consume service-tier memory and still need volume analysis.
Anti Pattern
A temporary record used only through SetRange(KeyField, X); FindFirst() to retrieve one scalar value, with no record semantics that justify the table. The opposite mistake is replacing a temporary table that needs filtering or ordered iteration with a dictionary.
Changed by
- #94 Correct performance knowledge guidance, 2026-07-14
From microsoft/BCQuality at a4593a1, MIT License, Copyright (c) 2026 Microsoft Corporation (license).