bcquality/microsoft/knowledge/performance/pass-var-record-to-preserve-partial-load-enumerator.md
Jesper Schulz-Wedde b6da405376 Improve partner onboarding and documentation navigation
Lead with a complete plugin quick start and add task-oriented usage, troubleshooting, customization, and contribution guides. Preserve the broader plugin framing, correct conflicting contract guidance, support Agents folder reviews, and align repository validation. Convert existing sample references to clickable links without changing knowledge rules.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-09-09 17:25:29 +02:00

1.6 KiB

bc-version domain keywords technologies countries application-area
all
performance
setloadfields
jit-load
enumerator
var-parameter
pass-by-value
next
al
w1
all

Pass the iterated record var so a JIT load updates the enumerator

Contributions welcome — open a PR to refine or extend this article.

Description

A FindSet/Next loop builds an enumerator from the fields selected for load. Accessing an unloaded field triggers a JIT load. When the record is passed by value, the copy does not share that enumerator: the JIT loads the copy and leaves the enumerator unchanged, so every later Next() JIT-loads again. Passing var lets the first JIT update the enumerator. AddLoadFields on the original record before a by-value call is the other fix. This is independent of whether SetLoadFields was ordered before filters.

Best Practice

Helpers that read extra fields on an in-flight iterator must take the record as var, or the caller must AddLoadFields those fields before the loop. Prefer declaring the extra fields up front so no JIT is needed.

See sample: pass-var-record-to-preserve-partial-load-enumerator.good.al.

Anti Pattern

A SetLoadFields loop that passes the iterator by value into a helper which then reads a field that was not loaded. The first row pays one JIT; every subsequent row pays it again because the enumerator never learned the extra field.

See sample: pass-var-record-to-preserve-partial-load-enumerator.bad.al.