bcquality/microsoft/knowledge/performance/prefer-dictionary-over-temporary-table-for-lookups.md
Jesper Schulz-Wedde 3f0b6a41db Correct performance knowledge guidance
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 667c64a8-eb36-4440-bc41-6a97d8fb5542
2026-07-14 11:18:52 +02:00

1.2 KiB

bc-version domain keywords technologies countries application-area
all
performance
dictionary
temporary-table
lookup
o-of-1
key-lookup
al
w1
all

Prefer a Dictionary over a temporary table for pure lookups

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.