bcquality/microsoft/knowledge/performance/use-dictionary-for-temporary-identity-lookups.md
Jesper Schulz-Wedde 5bcdc55df9 Sync knowledge articles with review agent instructions
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-05 14:08:32 +02:00

1.2 KiB

bc-version domain keywords technologies countries application-area
all
performance
dictionary
temporary-table
lookup
identity
o1
al
w1
all

Use Dictionary for temporary identity lookups

Description

A temporary record is useful when code needs record semantics: filters, keys, FlowFields, or table-shaped buffers. When the only operation is "have I seen this key?" or "what value belongs to this key?", a Dictionary is the simpler and faster structure. Dictionary lookup is O(1) by key, while a temporary table still pays record and key-management overhead.

Best Practice

Use Dictionary for in-memory lookup sets and maps whose keys fit in memory and whose access pattern is by identity. Keep temporary tables for data that needs table APIs, multiple keys, filter expressions, or later processing as records.

See sample: use-dictionary-for-temporary-identity-lookups.good.al.

Anti Pattern

Creating a temporary table solely to call Get or FindFirst by a single key in a loop. The code looks familiar to AL developers, but it is heavier than the lookup problem requires.

See sample: use-dictionary-for-temporary-identity-lookups.bad.al.