diff --git a/AyCode.Core/Serializers/Binaries/AcBinarySerializer.BinarySerializationContext.cs b/AyCode.Core/Serializers/Binaries/AcBinarySerializer.BinarySerializationContext.cs index 3a8fea7..5b7e5c5 100644 --- a/AyCode.Core/Serializers/Binaries/AcBinarySerializer.BinarySerializationContext.cs +++ b/AyCode.Core/Serializers/Binaries/AcBinarySerializer.BinarySerializationContext.cs @@ -388,11 +388,21 @@ public static partial class AcBinarySerializer [MethodImpl(MethodImplOptions.AggressiveInlining)] public void WriteByte(byte value) { - if (_position >= _bufferEnd) - Output.Grow(ref _buffer, ref _position, ref _bufferEnd, 1); + if (_position >= _bufferEnd) GrowOne(); _buffer[_position++] = value; } + /// + /// Cold-path single-byte grow helper. Outlined from the hot-path 1-byte writers + /// (, / fast-paths) + /// so the inliner cost-models the hot path WITHOUT the 4-ref-arg Output.Grow call's + /// argument-prep IL. This keeps the per-property hot-path tight enough for AOT to inline the + /// write into the source-gen WriteProperties body across many call-sites — the cumulative + /// gain shows up on graph-heavy cells where every leaf serialises ~6 primitive properties. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + private void GrowOne() => Output.Grow(ref _buffer, ref _position, ref _bufferEnd, 1); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void WriteTwoBytes(byte b1, byte b2) { @@ -464,8 +474,7 @@ public static partial class AcBinarySerializer //if (FastWire) { WriteRaw(value); return; } if (value < 0x80) { - if (_position >= _bufferEnd) - Output.Grow(ref _buffer, ref _position, ref _bufferEnd, 1); + if (_position >= _bufferEnd) GrowOne(); _buffer[_position++] = (byte)value; return; } @@ -531,8 +540,7 @@ public static partial class AcBinarySerializer //if (FastWire) { WriteRaw(value); return; } if (value < 0x80) { - if (_position >= _bufferEnd) - Output.Grow(ref _buffer, ref _position, ref _bufferEnd, 1); + if (_position >= _bufferEnd) GrowOne(); _buffer[_position++] = (byte)value; return; }