Move hot-path exception messages into NoInlining throw helpers
Merged
BR
18d ago+81+81+01234567890123456789-21-21-01234567890123456789
What changed
- Adds
[MethodImpl(MethodImplOptions.NoInlining)]helpers toThrowHelper. Each holds its own message and forwards to the general throw helpers (ThrowInvalidDataException,ThrowInvalidOperationException,ThrowArgumentException,ThrowArgumentOutOfRangeException). This follows the existingThrowArgumentExceptionInsufficientOutputBufferandThrowInvalidDataExceptionIncompleteSnappyBlockpattern. - Replaces the inline-message throws in
SnappyCompressor,SnappyDecompressor,VarIntEncoding.ReadandHashTablewith calls to the new helpers.
Why
The hot methods still loaded the message strings and set up the arguments for each ThrowHelper call. With the messages moved into non-inlined helpers, a throw site in the hot method is a single call with no arguments. The input-too-large check in SnappyCompressor.Compress(ReadOnlySequence<byte>, IBufferWriter<byte>) also built an interpolated string ({uint.MaxValue} is not a constant), and that string building now happens only inside the helper.
Reviewer notes
- Exception types and message text are unchanged.
- The two argument-exception helpers still take
nameof(...)from the caller, matchingThrowArgumentExceptionInsufficientOutputBuffer. That leaves one constant string load at those two sites. SnappyDecompressor.ThrowCannotUseWithBufferWriterwas already a NoInlining wrapper and is unchanged.- Build has no warnings. All 1232 tests pass on net8.0, net9.0, net10.0 and net481. I haven't inspected the JIT disassembly.
š¤ Generated with Claude Code