Skip to content

Optimize generated scalar getters - #17

Merged
RejectKid merged 1 commit into
masterfrom
agent/optimize-generated-getters
Jul 21, 2026
Merged

Optimize generated scalar getters#17
RejectKid merged 1 commit into
masterfrom
agent/optimize-generated-getters

Conversation

@RejectKid

@RejectKid RejectKid commented Jul 21, 2026

Copy link
Copy Markdown
Owner

What changed

  • emit direct mask-and-shift expressions for generated integral-backed LSB and MSB getters, including integral, enum, and Boolean properties
  • fix Boolean getters backed by signed integral fields so a set one-bit field reads as true
  • expand generated-accessor benchmarks to cover signed and unsigned integers, Boolean, enum, MSB, Memory<byte>, and inline-array models
  • compare equivalent models compiled by the original and current source generators in the performance-regression harness, with focused method filtering
  • update benchmark and contributor documentation

Why

Generated scalar getters previously delegated to general-purpose BitPrimitives methods even though their offsets, widths, orders, and backing types are compile-time constants. Emitting the operation directly gives the JIT a smaller accessor and avoids an extra helper call in Tier-0 code. It also fixes the signed one-bit Boolean case, where comparing a sign-extended -1 result with 1 returned false.

For the representative generated UInt32 MSB getter, disassembly changed from a 45-byte accessor that called BitPrimitives.ReadUInt32MSB to a 25-byte, call-free bswap/shift sequence. Tier-1 throughput remains effectively tied because the JIT already inlined the old helper.

Validation

  • dotnet build BitsKit.sln -c Release --no-restore — succeeded with 0 warnings
  • dotnet test BitsKit.Tests/BitsKit.Tests.csproj -c Release --framework net8.0 — 4,587 passed
  • dotnet test BitsKit.Tests/BitsKit.Tests.csproj -c Release --framework net10.0 — 4,587 passed
  • focused Short generated-accessor comparison — 10 operations, geometric mean 0.29% faster, no regression beyond 5%
  • full Dry original/current harness validation — all 66 comparable operations discovered and executed

@RejectKid
RejectKid marked this pull request as ready for review July 21, 2026 20:48
@RejectKid
RejectKid merged commit a2b5462 into master Jul 21, 2026
8 checks passed
@RejectKid
RejectKid deleted the agent/optimize-generated-getters branch July 21, 2026 20:48
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