refactor(syntax): replace `nonmax` crate with zero-cost non-max types
Replace nonmax crate with own NonMax* types.
nonmax's NonMax* types work by storing the value internally as a NonZero*, and inverting the bits on every read/write (native_u32 = nonmax_u32 as u32 ^ u32::MAX). This reserves only a single illegal value, but has (small) runtime cost on every read/write.
The NonMax* types provided here make a different trade-off.
NonMaxU8 wraps an enum with a single illegal value (255). All the other types store the value as a number of u8s + a single NonMaxU8 as highest byte. i.e. they reserve all values which have 255 as the highest byte.
NonMaxU8can represent the values0to254.NonMaxU16can represent the values0to(255 << 8) - 1.NonMaxU32can represent the values0to(255 << 24) - 1.NonMaxU64can represent the values0to(255 << 56) - 1.NonMaxU128can represent the values0to(255 << 120) - 1.
We trade approx 0.4% of the legal range being unavailable, in return for zero runtime cost when reading or writing the values.
Linter snapshot change is because PreferHooksInOrder rule uses a hash map keyed by ScopeId. The hash of NonMaxU32 is now same as hash of u32, which alters the hash map iteration order. This does not change what errors are output, only the order they're output in.
Your org has enabled the Graphite merge queue for merging into main
Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.
You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.
This stack of pull requests is managed by Graphite. Learn more about stacking.
Join @overlookmotel and the rest of your teammates on
Graphite
CodSpeed Performance Report
Merging #5760 will degrade performances by 3.53%
Comparing 09-13-refactor_syntax_replace_nonmax_crate_with_zero-cost_non-max_types (5cd101d) with main (8d026e1)
Summary
❌ 1 regressions
✅ 28 untouched benchmarks
:warning: Please fix the performance issues or acknowledge them on CodSpeed.
Benchmarks breakdown
| Benchmark | main |
09-13-refactor_syntax_replace_nonmax_crate_with_zero-cost_non-max_types |
Change | |
|---|---|---|---|---|
| ❌ | codegen[checker.ts] |
20.6 ms | 21.4 ms | -3.53% |
-3% on some benchmarks. Zero cost my arse! I'll try to figure out why.
Close as stale.
Archived on overlookmotel/non-max-id-types branch.