Skip to content

perf: Flatten internal Lazy<bool> fields in UnionCaseArgInfo#299

Open
dimension-zero wants to merge 1 commit into
fsprojects:masterfrom
dimension-zero:pr/01-lazy-bool-flatten
Open

perf: Flatten internal Lazy<bool> fields in UnionCaseArgInfo#299
dimension-zero wants to merge 1 commit into
fsprojects:masterfrom
dimension-zero:pr/01-lazy-bool-flatten

Conversation

@dimension-zero
Copy link
Copy Markdown
Contributor

Summary

Seven boolean-valued fields on the internal UnionCaseArgInfo were each Lazy<bool> even though their bodies only inspect already-cached attribute arrays. Make them strict bool:

  • IsRest, AppSettingsCSV, IsMandatory, IsInherited, IsUnique, IsHidden, GatherAllSources

Lazy<_> fields whose bodies raise validation errors (CustomAssignmentSeparator, IsGatherUnrecognized, CliPosition, MainCommandName, ParameterInfo, etc.) remain Lazy<_> so error-emission timing is unchanged for the checkStructure=false consumers.

Public ArgumentCaseInfo keeps Lazy<bool> for binary compatibility — ToArgumentCaseInfo() wraps the strict bools with lazy ... at the boundary.

Why

Each Lazy<bool> was a heap allocation that boxed a primitive, with no deferral benefit — checkUnionArgInfo forces every one on the default construction path anyway. The criticism in the original review was that the lazy graph wasn't carrying its weight; this commit flattens the seven flags that are safe to flatten without changing observable behaviour.

Test plan

  • dotnet build -c Release — clean (0 warnings)
  • dotnet test -c Release — 112/112 pass

The seven boolean-valued fields on `UnionCaseArgInfo`
(`IsRest`, `AppSettingsCSV`, `IsMandatory`, `IsInherited`, `IsUnique`,
`IsHidden`, `GatherAllSources`) were each wrapped in `Lazy<bool>` even
though their bodies only inspect already-cached attribute arrays. Each
wrapper allocated a heap object per case and `checkUnionArgInfo` forced
every one on the default construction path, so the deferral was
buying nothing.

Make them strict `bool`. The more complex `Lazy<_>` fields whose bodies
raise validation errors (`CustomAssignmentSeparator`, `IsGatherUnrecognized`,
`CliPosition`, `MainCommandName`, `ParameterInfo`, etc.) remain
`Lazy<_>` so error-emission timing is unchanged for `checkStructure=false`
consumers.

The public `ArgumentCaseInfo` type keeps `Lazy<bool>` for binary
compatibility — `ToArgumentCaseInfo()` wraps the strict bools with
`lazy ...` at the boundary.
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