Repository navigation
Releases
v2.1.0 - Up to 6x faster initialization and less memory
⚠️ Breaking changes
- Target frameworks are now
net10.0andnet11.0. .NET 8 and .NET 9 are no longer supported.
🚀 Performance improvements
The Reflection API (FastEnum.Xxx<T>() and the extension methods) has been reworked internally. The public API is unchanged.
Faster initialization, less memory
The first call for each enum type is much cheaper, because:
- LINQ and
FrozenDictionaryare no longer used to build the lookup tables, so less code is JIT-compiled for each enum type. - The lookup table by value is no longer built when the values are continuous.
EnumMemberAttribute,LabelAttributeand the UTF-8 name are now read the first time they are used, not up front.
Measured on the first call of each API for an enum type (median of 30 runs, each in a new process):
| First API called | 16 fields (continuous) | 16 fields (discontinuous) | 128 fields (continuous) | 128 fields (discontinuous) |
|---|---|---|---|---|
GetName |
17.7 → 3.1 ms (5.6x) | 18.2 → 7.4 ms (2.5x) | 18.8 → 3.3 ms (5.7x) | 19.4 → 7.5 ms (2.6x) |
TryParse |
17.8 → 2.9 ms (6.1x) | 17.8 → 6.8 ms (2.6x) | 18.6 → 3.0 ms (6.2x) | 18.7 → 6.8 ms (2.7x) |
GetMembers |
17.3 → 2.7 ms (6.4x) | 17.6 → 6.6 ms (2.7x) | 18.3 → 2.9 ms (6.4x) | 18.6 → 6.7 ms (2.8x) |
For the very first enum type in a process, which includes loading FastEnum itself, GetName goes from 41 ms to 12–17 ms (2.5–3.4x faster).
| Memory per enum type | 16 fields (continuous) | 16 fields (discontinuous) | 128 fields (continuous) | 128 fields (discontinuous) |
|---|---|---|---|---|
| Allocated during initialization | 18.7 → 7.6 KB (−59%) | 21.2 → 11.0 KB (−48%) | 189 → 55 KB (−71%) | 209 → 64 KB (−69%) |
| Retained after GC | 9.4 → 6.5 KB (−31%) | 12.0 → 9.9 KB (−18%) | 59.5 → 47.9 KB (−20%) | 79.9 → 57.1 KB (−29%) |
Faster lookups
A new hash table built for enum values replaces FrozenDictionary. Comparing names while ignoring case is also faster.
| API | v2.0.8 | v2.1.0 | Change |
|---|---|---|---|
GetMember() / ToMember() (discontinuous values) |
2.04 ns | 1.03 ns | −50% |
ToString() / FastToString() (discontinuous values) |
1.68 ns | 1.14 ns | −32% |
GetLabel() (discontinuous values) |
3.00 ns | 2.10 ns | −30% |
GetName() / ToName() (discontinuous values) |
1.29 ns | 1.07 ns | −17% |
TryParse(ignoreCase: true) |
9.00 ns | 7.58 ns | −16% |
TryParse(ignoreCase: true) (constant input) |
7.56 ns | 4.36 ns | −42% |
The other APIs perform the same as before.
Note
Because attributes are now read the first time they are used, GetEnumMemberValue() and GetLabel() can be about 0.3 ns slower than before.
How it was measured
- AMD EPYC 7763, Windows 11, .NET 11.0.0, BenchmarkDotNet 0.16.0-preview.2
- v2.0.8 has no
net11.0build, so itsnet10.0build was used. This is what a .NET 11 app gets from the v2.0.8 package. - Initialization times include JIT compilation, and the absolute values depend on the machine.
- The Source Generator version (
FastEnum.Generators) is not included, because it has not changed.
🙏 Contributors
Thanks to @akeit0 for #131 and #132!
📝 What's Changed
- Fix
.GetName()/.GetMember()/.ToString()returning a wrong member for large 64-bit values by @xin9le in #110 - Speed up case-insensitive
.TryParse()with an ASCII fast path by @xin9le in #111 - Add non constant input benchmark by @xin9le in #112
- Hello, .NET 11 & Goodbye .NET 8 / .NET 9 by @xin9le in #113
- Minor refactorings by @xin9le in #114
- Replace
FrozenDictionarywithEnumKeyDictionaryfor value lookup of non-continuous enums by @xin9le in #115 - Use
nuintindices for array lookups to eliminate sign/zero-extension instructions by @xin9le in #116 - Benchmark under .NET 11 by @xin9le in #117
- Remove the table load and
nullcheck fromEnumKeyDictionarylookups by @xin9le in #118 - Skip building the value dictionary for continuous enums by @xin9le in #119
- Rename:
EnumKeyDictionary->EnumKeyDictionaryHelperby @xin9le in #120 - Take
EnumInfo<T>min / max from the sorted members instead of LINQ by @xin9le in #121 - Reduce
Member<T>initialization cost by @xin9le in #122 - Fix the bucket count of the case-insensitive name dictionary and build the name dictionaries without LINQ by @xin9le in #123
- Replace LINQ in building s_orderedMembers to cut per-enum initialization cost by half by @xin9le in #124
- Eliminate per-enum JIT cost in dictionary construction via
IMemberName/IMemberValue<T>by @xin9le in #125 - Consolidate per-enum JIT helpers into
JitOptimizationand keepToUInt64JIT-friendly by @xin9le in #126 MemberHelperis moved toJitOptimizationby @xin9le in #127- Lazy initialization for
Member<T>.NameUtf8/EnumMemberAttribute/Labelsby @xin9le in #128 - Remove unnecessary
AggressiveInliningby @xin9le in #129 - Refactor
FastEnumBoosterGenerator.Generateinto static local functions by @xin9le in #130 - Use generic Enum.GetValues for Native AOT by @akeit0 in #131
- Update description for source code generation by @xin9le in #133
- Share enum initialization by underlying width by @akeit0 in #132
- Refactor
EnumInfo<T>initialization and member ordering by @xin9le in #134 - Declare Native AOT compatibility for
FastEnum.Coreby @xin9le in #135 - Replace the T4-generated
UnderlyingOperationwith generic math by @xin9le in #136
Full Changelog: v2.0.8...v2.1.0
v2.0.8
v2.0.7
What's Changed
- Specify commit hash by @xin9le in #91
- Update NuGet packages by @xin9le in #92
- Refactor benchmark configuration by @xin9le in #93
- Improve
GetHashCodeperformance by @xin9le in #94 - Improve range checking by @xin9le in #95
- Improve
.ToNumberString()performance by @xin9le in #96 - Improve
.IsDefined(ReadOnlySpan<char>)performance by @xin9le in #97 - Improve
.TryParseName()performance by @xin9le in #98 - Add reflection benchmark by @xin9le in #99
- Using .NET 10 runtime explicitly by @xin9le in #100
- Suppress CA1069 warning by @xin9le in #101
- Use
FrozenDictionary<K,V>in .NET 10 instead ofFastReadOnlyDictionary<K,V>by @xin9le in #102 - Update NuGet packages by @xin9le in #103
- Release v2.0.7 by @xin9le in #104
Full Changelog: v2.0.6...v2.0.7
v2.0.6
What's Changed
- goto Shouldly; by @xin9le in #74
- Prefer constant values by @xin9le in #75
- Suppress IDE0305 by @xin9le in #76
- Refine .editoconfig by @xin9le in #78
- Move to
.slnxby @xin9le in #79 - Update NuGet packages by @xin9le in #80
- Update NuGet packages by @xin9le in #81
- Add FUNDING.yml by @xin9le in #82
- Add setting files to .slnx by @xin9le in #83
- Support .NET 10 by @xin9le in #84
- Enable artifacts output by @xin9le in #85
- Update NuGet Packages by @xin9le in #86
- Enable method level parallel unit testing explicitly by @xin9le in #87
- Add specialized cictionary benchmark by @xin9le in #88
- Remove unnecessary pragma by @xin9le in #89
- Release v2.0.6 by @xin9le in #90
Full Changelog: v2.0.5...v2.0.6
v2.0.5
What's Changed
- Update nuget packages by @xin9le in #64
- Prefer
Unsafe.BitCast()toUnsafe.As()by @xin9le in #65 - Optimize ThrowIfUnderlyingTypeMismatch by @akeit0 in #66
- Micro refactor by @xin9le in #67
- Improve the initial performance of
.GetUnderlyingType<T>()method by @xin9le in #68 - Release : v2.0.5 by @xin9le in #69
New Contributors
Full Changelog: v2.0.4...v2.0.5
v2.0.4
What's Changed
- Enhance code coverages by @xin9le in #57
- Fix README by @prozolic in #59
- Improve test cases by @xin9le in #61
- Safeguard for case-insensitive dictionary generation by @xin9le in #60
- Refactor unit testing by @xin9le in #62
- Release : v2.0.4 by @xin9le in #63
New Contributors
Full Changelog: v2.0.3...v2.0.4
v2.0.3
v2.0.2
v2.0.1
v2.0.0
What's Changed
- Change directory structure by @xin9le in #14
- Fix: GitHub Actions by @xin9le in #15
- v2 Preview1 by @xin9le in #16
- Fix : GitHub Actions by @xin9le in #17
- Fix NuGet toolchain by @xin9le in #18
- Return
ImmutableArray<T>by @xin9le in #19 - Add enum member name as UTF-8 byte array by @xin9le in #20
- Micro improvements by @xin9le in #21
- Improve dictionary performance by @xin9le in #22
- Support
ReadOnlySpan<char>by @xin9le in #23 - Remove unnecessary attribute by @xin9le in #24
- Rename file / class by @xin9le in #25
- Release : v2.0.0 Preview2 by @xin9le in #26
- Separate StringHelpers types into another files. by @xin9le in #27
- Use indexer without range check by @xin9le in #28
- Micro refactoring by @xin9le in #29
- Should support ASCII digit only by @xin9le in #30
- Support Only .NET 8 by @xin9le in #31
- Support UTF-8 byte sequence by @xin9le in #32
- Speed up numeric check by @xin9le in #33
- Remove unnecessary dependency by @xin9le in #34
- Release : v2.0.0 Preview3 by @xin9le in #35
- Omit
ReadOnlySpan<byte>overloads by @xin9le in #36 - Remove unnecessary
ReadOnlySpan<byte>overloads by @xin9le in #37 - Refactor
.ToString()by @xin9le in #38 - Refactor
StringHelpertype by @xin9le in #39 - Support Source Generator implementation by @xin9le in #40
- Fix error in equivalence evaluation by @xin9le in #43
- README for v2 by @xin9le in #42
- Fit NuGet package creation for source generator by @xin9le in #41
- Release : v2.0.0 by @xin9le in #44
Full Changelog: v1.8.0...v2.0.0