Skip to content

feat(PC0030): report partial-record suggestions on Next() loops only - #678

Merged
Arthurvdv merged 4 commits into
mainfrom
feat/pc0030-loops-only
Nov 24, 2026
Merged

Arthurvdv merged 4 commits into
mainfrom
feat/pc0030-loops-only

Conversation

@Arthurvdv

@Arthurvdv Arthurvdv commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

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 were Get. The investigation report (BC 29.1, BCPerfTool) shows where partial records actually pay off:

Read shape Effect of SetLoadFields
Loop over many rows (read + Next()) 5-8x faster, more with table extensions
Single record by full primary key no measurable gain, stays cached
Single record with any other filter no gain; repeated reads lose the NST data cache (60-90x slower)

A follow-up run (suite G) measured the loop entry method: FindSet, Find('-'), Find('+'), FindFirst, FindLast and Get followed by a Next() loop all give the same 8x gain with identical statement counts, and a FindSet without Next behaves 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.

  • New analyzer UsePartialRecordsForLoops (rename of UsePartialRecordsOnRead): a read on a tracked local is pending until a built-in Next on the same variable runs inside a loop that does not contain the read (loop-depth rule); only confirmed reads are reported. Covers if FindSet then repeat, if not FindSet then exit; repeat, statement form, while Next <> 0, until (Next = 0) or Stop, Next as a statement in a while body, reads in either branch before one loop. A Get inside its own loop body, FindFirst(); Next();, and any read without a Next loop are not reported.
  • Suppressions carried over: SetLoadFields/AddLoadFields/SetBaseLoadFields before 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.LocalVariable receivers. Simplification: RecordRef.SetTable(...) counts as a write instead of linking to the target record's state.
  • Syntax pre-filter: a body without an identifier named Next is never bound.
  • PartialRecordOperations slimmed to PC0031 and renamed PartialRecordsCauseJitLoad; PC0031 behaviour and its 32 fixtures are unchanged.
  • CodeFix renamed; logic unchanged (insert before the read's statement, wrap embedded statements, custom Fix All).
  • Resx: new title Use partial records when looping over records, message and description describe the loop scope and the cache trade-off.
  • Fixtures: existing scenarios converted to loop form so each still tests its suppression; the single-read HasDiagnostic fixtures moved to NoDiagnostic; new loop shapes and non-reports added (47 HasDiagnostic, 63 NoDiagnostic, 32 HasFix, 6 HasFixAll, 5 NoFix).
  • Rule doc rewritten (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-changes clean.
  • PlatformCop Release build with ContinuousIntegrationBuild=true (netstandard2.1, net8.0, net10.0): 0 warnings.
  • PC0030 and PC0031 tests also run against the net8.0 SDK leg: 179/179.
  • Validate-Rules.ps1: OK.
  • Before writing the analyzer, 15 new NoDiagnostic fixtures were confirmed to fail against the old analyzer.

🤖 Generated with Claude Code

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]>
Arthurvdv and others added 3 commits November 22, 2026 16:21
…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
Arthurvdv merged commit b6c0926 into main Nov 24, 2026
53 checks passed
@Arthurvdv
Arthurvdv deleted the feat/pc0030-loops-only branch November 24, 2026 15:16
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant