Disable FastWire mode; enforce compact encoding only

All FastWire-related code paths, fields, and options have been commented out in both AcBinarySerializer and AcBinaryDeserializer. This removes support for fixed-width integer and UTF-16 encoding, forcing the use of compact VarInt and UTF-8 encoding exclusively. The WireMode option is also commented out, so FastWire can no longer be selected. This change reduces output size and simplifies the codebase, but may impact serialization/deserialization speed for some scenarios.
This commit is contained in:
Loretta 2026-02-17 15:25:51 +01:00
parent 98d7a27245
commit 418d9f839a
5 changed files with 44 additions and 40 deletions

View File

@ -198,7 +198,8 @@ public static partial class AcBinaryDeserializer
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int ReadVarInt()
{
if (FastWire) { return ReadRaw<int>(); }
//if (FastWire) { return ReadRaw<int>(); }
var raw = ReadVarUInt();
var value = (int)(raw >> 1) ^ -(int)(raw & 1);
return value;
@ -207,7 +208,8 @@ public static partial class AcBinaryDeserializer
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public uint ReadVarUInt()
{
if (FastWire) { return ReadRaw<uint>(); }
//if (FastWire) { return ReadRaw<uint>(); }
// Fast path: single byte (0-127) - ~70% of cases
var b0 = _buffer[_position];
if ((b0 & 0x80) == 0)
@ -257,7 +259,8 @@ public static partial class AcBinaryDeserializer
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long ReadVarLong()
{
if (FastWire) { return ReadRaw<long>(); }
//if (FastWire) { return ReadRaw<long>(); }
var raw = ReadVarULong();
var value = (long)(raw >> 1) ^ -((long)raw & 1);
return value;
@ -266,7 +269,8 @@ public static partial class AcBinaryDeserializer
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ulong ReadVarULong()
{
if (FastWire) { return ReadRaw<ulong>(); }
//if (FastWire) { return ReadRaw<ulong>(); }
ulong value = 0;
var shift = 0;
while (true)
@ -326,15 +330,15 @@ public static partial class AcBinaryDeserializer
}
// FastWire: length is char count, data is UTF-16 (2 bytes per char)
if (FastWire)
{
var byteLen = length * 2;
EnsureAvailable(byteLen);
var chars = MemoryMarshal.Cast<byte, char>(_buffer.AsSpan(_position, byteLen));
var value = new string(chars);
_position += byteLen;
return value;
}
//if (FastWire)
//{
// var byteLen = length * 2;
// EnsureAvailable(byteLen);
// var chars = MemoryMarshal.Cast<byte, char>(_buffer.AsSpan(_position, byteLen));
// var value = new string(chars);
// _position += byteLen;
// return value;
//}
EnsureAvailable(length);

View File

@ -63,7 +63,7 @@ public static partial class AcBinaryDeserializer
public bool HasMetadata;
public bool IsMergeMode;
public bool RemoveOrphanedItems;
public bool FastWire;
//public bool FastWire;
// Options-derived properties
public byte MinStringInternLength => Options.MinStringInternLength;
@ -139,7 +139,7 @@ public static partial class AcBinaryDeserializer
HasMetadata = false;
IsMergeMode = false;
RemoveOrphanedItems = false;
FastWire = Options.WireMode == WireMode.Fast;
//FastWire = Options.WireMode == WireMode.Fast;
ChainTracker = null;
}

View File

@ -227,7 +227,7 @@ public static partial class AcBinarySerializer
/// Reference handling is safe because generated code inlines TryConsumeWritePlanEntry for IId types.
/// </summary>
public bool IsDirectObjectWrite => !UseMetadata && !HasPropertyFilter;
public bool FastWire { get; private set; }
//public bool FastWire { get; private set; }
public byte MinStringInternLength => Options.MinStringInternLength;
public byte MaxStringInternLength => Options.MaxStringInternLength;
public BinaryPropertyFilter? PropertyFilter => Options.PropertyFilter;
@ -250,7 +250,7 @@ public static partial class AcBinarySerializer
public BinarySerializationContext(AcBinarySerializerOptions options)
{
Reset(options);
FastWire = options.WireMode == WireMode.Fast;
//FastWire = options.WireMode == WireMode.Fast;
}
/// <summary>
@ -264,7 +264,7 @@ public static partial class AcBinarySerializer
// IMPORTANT: base.Reset sets Options first, so derived code can use Options-derived properties
base.Reset(options);
HasPropertyFilter = Options.PropertyFilter != null;
FastWire = Options.WireMode == WireMode.Fast;
//FastWire = Options.WireMode == WireMode.Fast;
}
public override void Clear()
@ -389,7 +389,7 @@ public static partial class AcBinarySerializer
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void WriteVarUInt(uint value)
{
if (FastWire) { WriteRaw(value); return; }
//if (FastWire) { WriteRaw(value); return; }
if (value < 0x80)
{
if (_position >= _bufferEnd)
@ -409,7 +409,7 @@ public static partial class AcBinarySerializer
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void WriteVarInt(int value)
{
if (FastWire) { WriteRaw(value); return; }
//if (FastWire) { WriteRaw(value); return; }
var encoded = (uint)((value << 1) ^ (value >> 31));
WriteVarUInt(encoded);
}
@ -417,7 +417,7 @@ public static partial class AcBinarySerializer
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void WriteVarULong(ulong value)
{
if (FastWire) { WriteRaw(value); return; }
//if (FastWire) { WriteRaw(value); return; }
if (value < 0x80)
{
if (_position >= _bufferEnd)
@ -437,7 +437,7 @@ public static partial class AcBinarySerializer
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void WriteVarLong(long value)
{
if (FastWire) { WriteRaw(value); return; }
//if (FastWire) { WriteRaw(value); return; }
var encoded = (ulong)((value << 1) ^ (value >> 63));
WriteVarULong(encoded);
}
@ -488,17 +488,17 @@ public static partial class AcBinarySerializer
public void WriteStringUtf8(string value)
{
if (FastWire)
{
// UTF-16: char count (fixed uint) + raw char data (zero-encoding memcopy)
var charLen = value.Length;
var byteLen = charLen * 2;
WriteRaw(charLen);
EnsureCapacity(byteLen);
MemoryMarshal.AsBytes(value.AsSpan()).CopyTo(_buffer.AsSpan(_position, byteLen));
_position += byteLen;
return;
}
//if (FastWire)
//{
// // UTF-16: char count (fixed uint) + raw char data (zero-encoding memcopy)
// var charLen = value.Length;
// var byteLen = charLen * 2;
// WriteRaw(charLen);
// EnsureCapacity(byteLen);
// MemoryMarshal.AsBytes(value.AsSpan()).CopyTo(_buffer.AsSpan(_position, byteLen));
// _position += byteLen;
// return;
//}
var charLength = value.Length;

View File

@ -971,12 +971,12 @@ public static partial class AcBinarySerializer
}
// FastWire: skip FixStr optimization (UTF-8 specific), write String marker + UTF-16 data
if (context.FastWire)
{
context.WriteByte(BinaryTypeCode.String);
context.WriteStringUtf8(value);
return;
}
//if (context.FastWire)
//{
// context.WriteByte(BinaryTypeCode.String);
// context.WriteStringUtf8(value);
// return;
//}
// Fast path for short strings: check length first (cheap), then ASCII
// FixStr encodes type+length in single byte for strings <= 31 chars

View File

@ -100,7 +100,7 @@ public sealed class AcBinarySerializerOptions : AcSerializerOptions
/// Compact: VarInt + UTF-8 (default, smaller output).
/// Fast: Fixed-width integers + UTF-16 (larger output, faster encode/decode).
/// </summary>
public WireMode WireMode { get; set; } = WireMode.Fast;
//public WireMode WireMode { get; set; } = WireMode.Compact;
/// <summary>
/// When true, checks for duplicate property name hashes during serialization (UseMetadata mode).