Skip to content

Share enum initialization by underlying width - #132

Merged
xin9le merged 2 commits into
xin9le:mainfrom
akeit0:feature/shared-generics
Nov 24, 2026
Merged

xin9le merged 2 commits into
xin9le:mainfrom
akeit0:feature/shared-generics

Conversation

@akeit0

@akeit0 akeit0 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Share enum initialization by underlying width

Continues #77 by sharing enum member ordering and continuity checks across types with the same backing width. Adds regression coverage for signed ranges and alias selection.

Results

.NET 11.0.0 on Windows x64, Release. Medians from 15 fresh processes per variant. First use measures FastEnum.IsContinuous<T>(). Both benchmark builds include the separate Native AOT fix in #131. The control starts at b488d4d.

Enum types JIT first use (µs/type) Native AOT first use (µs/type) Native AOT executable size
8 1,450.25 → 1,003.91 (−30.8%) 13.31 → 13.25 (−0.5%) −8.5 KiB (−0.42%)
128 1,358.95 → 784.42 (−42.3%) 10.77 → 10.27 (−4.6%) −131 KiB (−3.28%)

Median first-use allocations fell by 20 B/type under JIT and 14 B/type under Native AOT. One 128-type JIT run allocated more than the control. Warm lookups allocated 0 B/op.

Memory breakdown at 128 enum types

A separate memory probe used 11 fresh processes per variant. JIT machine-code totals were identical across three EventPipe traces per variant.

Metric Control → shared generics
JIT managed allocation / retention (B/type) 2,163.31 → 2,143.31 / 1,711.19 → 1,691.19
Native AOT managed allocation / retention (B/type) 9,233.69 → 9,219.69 / 5,146.38 → 5,132.38
JIT machine code emitted during initialization 455,345 → 377,554 B (−17.1%)
Native AOT compiled method bodies 1,834,766 → 1,727,697 B (−5.8%)
Native AOT read-only data (.rdata) 1,480,114 → 1,465,922 B
Native AOT writable data (.data) 237,800 → 237,800 B

Estimated JIT private native data grew by 964 → 972 KiB during initialization, with overlapping run ranges. Native AOT private commit grew by 1,768 KiB in both variants.

All 635 tests passed on each of .NET 10 and .NET 11.

Read enum values through their unsigned storage type to share ordering and continuity checks across enum types.
@akeit0
akeit0 marked this pull request as ready for review November 23, 2026 10:48
@xin9le xin9le self-assigned this Nov 24, 2026
@xin9le xin9le added the enhancement New feature or request label Nov 24, 2026
@xin9le
xin9le merged commit 6c84ecb into xin9le:main Nov 24, 2026
2 checks passed

@xin9le xin9le left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! That's a really nice idea, and I appreciate your contribution!

Actually, I'd been thinking about determining s_isContinuous inside .ToOrderedMembers() too. But I didn't like how it looked to return it via an out parameter, so I held off on it. Seeing your PR made me realize I should've given it another look.

@akeit0
akeit0 deleted the feature/shared-generics branch November 24, 2026 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants