Skip to content

Optimize aligned memory accessors - #19

Merged
RejectKid merged 1 commit into
masterfrom
optimize-aligned-memory-accessors
Jul 22, 2026
Merged

Optimize aligned memory accessors#19
RejectKid merged 1 commit into
masterfrom
optimize-aligned-memory-accessors

Conversation

@RejectKid

Copy link
Copy Markdown
Owner

What changed

  • generate direct endian-aware reads and writes for byte-aligned, full-width Memory<byte> fields
  • support signed and unsigned integral fields, enums, both bit orders, nonzero byte offsets, and read-only getters
  • add focused UInt32 and UInt64 generated-accessor benchmarks
  • include the new benchmarks in the original-performance regression harness
  • add randomized generator correctness coverage

Why

Generated accessors for aligned memory fields previously routed through the general-purpose bit primitives. Because field width, offset, and bit order are compile-time constants, the generator can emit direct BinaryPrimitives operations and avoid the general extraction/write path.

Performance

Paired BenchmarkDotNet MediumRun results on AMD Ryzen 9 9900X / .NET 10:

Operation Before After Improvement
UInt32 get 0.8491 ns 0.7776 ns 8.4%
UInt64 get 0.8433 ns 0.7925 ns 6.0%
UInt32 set 0.9716 ns 0.8385 ns 13.7%
UInt64 set 1.0299 ns 0.8697 ns 15.6%

All measured operations remain allocation-free.

Validation

  • dotnet test BitsKit.Tests/BitsKit.Tests.csproj -c Release --no-restore
  • 4,588 tests passed on .NET 8
  • 4,588 tests passed on .NET 10
  • dotnet build BitsKit.sln -c Release --no-restore
  • git diff --check

@RejectKid
RejectKid marked this pull request as ready for review July 22, 2026 02:10
@RejectKid
RejectKid merged commit 9179007 into master Jul 22, 2026
8 checks passed
@RejectKid
RejectKid deleted the optimize-aligned-memory-accessors branch July 22, 2026 02:10
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