Repository navigation
feat(PC0030): report partial-record suggestions on Next() loops only - #678
Merged
Merged
Conversation
PC0030 reported every read on a local record without SetLoadFields. On BC 29.1 partial records only pay off when a loop reads many rows (5-8x faster, more with table extensions); single-record reads gain nothing, and repeated single-record reads that are not full-primary-key lookups bypass the NST data cache. The rule now reports a read only when a loop calls Next() on the same variable afterwards, whatever the read method (every entry method measured gives the same gain). - New analyzer UsePartialRecordsForLoops (rename of UsePartialRecordsOnRead; ID PC0030 and help URL unchanged): pending/confirmed read pairing under a loop-depth rule, syntax pre-filter on a Next identifier, same suppressions as before (writes, passes, exit, assignment, Clear/Reset, setup and reference tables), RecordRef SetTable treated as a write. - PartialRecordOperations slimmed to PC0031 and renamed to PartialRecordsCauseJitLoad; PC0031 behaviour and fixtures unchanged. - CodeFix renamed, logic unchanged. - Fixtures converted to loop form; single-record reads become NoDiagnostic; new loop shapes and non-reports added. - Rule docs and general guides updated. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ad-fields after the read Review round 1: the identifier scan is the cheap gate, so it now runs before the local-variable scan and its setup-table checks. A fixture pins that a SetLoadFields placed between the read and the loop does not cover the read. The rule doc records the superseded-in-one-branch merge, the write-after-loop clearing, the RecordRef decision and the inherited OperationWalker gap as known issues, and links the suite G results. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…on assignment Review round 2: for and foreach bounds run once before the loop, so a read inside them now records the outer depth. Assigning another record to the variable replaces its cursor, so its pending reads are dropped like Clear does. The rule doc cites Microsoft Learn for Reset clearing the load-field set, describes the whole-body field collection of the fix, and records that a read without parentheses gets no fix. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Review round 3: a read inside a loop body is never a loop driver, so it no longer survives the loop to be confirmed by a later nested Next. A FindSet followed by a Get on the same variable inside its own loop keeps reporting the FindSet, now pinned by a fixture. The CodeFix table records that Fix All inserts one call per reported read. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Arthurvdv
added a commit
to ALCops/alcops.dev
that referenced
this pull request
Nov 24, 2026
…-off (#239) Rewrites the PC0030 page for the loops-only scope: breaking change callout, why single-record reads are not reported (NST record cache, BC 29.1 measurements), a per-row loop example with the code fix, and the updated exception list. Companion to ALCops/Analyzers#678. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #531 (kept open until the release ships)
Why
PC0030 reported every read on a local record variable without
SetLoadFields, and in large apps most of those wereGet. The investigation report (BC 29.1, BCPerfTool) shows where partial records actually pay off:SetLoadFieldsNext())A follow-up run (suite G) measured the loop entry method:
FindSet,Find('-'),Find('+'),FindFirst,FindLastandGetfollowed by aNext()loop all give the same 8x gain with identical statement counts, and aFindSetwithoutNextbehaves like a single read. The loop is the signal, the entry method is not.What
Breaking change in what the rule reports. ID
PC0030, severity and help URL are unchanged.UsePartialRecordsForLoops(rename ofUsePartialRecordsOnRead): a read on a tracked local is pending until a built-inNexton the same variable runs inside a loop that does not contain the read (loop-depth rule); only confirmed reads are reported. Coversif FindSet then repeat,if not FindSet then exit; repeat, statement form,while Next <> 0,until (Next = 0) or Stop,Nextas a statement in awhilebody, reads in either branch before one loop. AGetinside its own loop body,FindFirst(); Next();, and any read without aNextloop are not reported.SetLoadFields/AddLoadFields/SetBaseLoadFieldsbefore the read (AND-merge), writes, table procedures, passing the variable, whole-record assignment,exit(Rec)(retroactive on the path),Clear/Reset, setup and reference tables, locals only,SymbolKind.LocalVariablereceivers. Simplification:RecordRef.SetTable(...)counts as a write instead of linking to the target record's state.Nextis never bound.PartialRecordOperationsslimmed to PC0031 and renamedPartialRecordsCauseJitLoad; PC0031 behaviour and its 32 fixtures are unchanged.pc0030-use-partial-records-for-loops.md); PC0031 doc now owns the shared flow-analysis notes; general guides updated.Companion docs PR: ALCops/alcops.dev#239
Verification
dotnet build ALCops.sln,dotnet test ALCops.sln(all cops green),dotnet format --verify-no-changesclean.ContinuousIntegrationBuild=true(netstandard2.1, net8.0, net10.0): 0 warnings.Validate-Rules.ps1: OK.🤖 Generated with Claude Code