fix(core): Adds SkipLocalsInitAttribute support, optimizes broadcasted packets (#363)
- [X] Adds support for `SkipLocalsInitAttribute`. SkipLocalsInitAttribute skips initializing stack variables including `stackalloc`. I don't think it is wired/working yet but should be implemented soon. - [X] Optimizes broadcasted packets by checking if the first byte (packet ID) is non-zero. If it is already set, it reuses the buffer. - [X] Removes unnecessary refs to Spans. I don't think the Span struct itself is mutable, so a ref is not helpful.
This commit is contained in:
parent
9c9591b098
commit
03d0a4664e
25 changed files with 478 additions and 285 deletions
|
|
@ -40,9 +40,20 @@ namespace Server.Network
|
|||
writer.Seek(length, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
// If LOCAL INIT is off, then stack/heap allocations have garbage data
|
||||
// Initializes the first byte (Packet ID) so it can be used as a flag.
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void InitializePacket(this Span<byte> buffer)
|
||||
{
|
||||
#if NO_LOCAL_INIT
|
||||
buffer[0] = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void InitializePackets(this Span<byte> buffer, int chunkLength)
|
||||
{
|
||||
#if NO_LOCAL_INIT
|
||||
var index = 0;
|
||||
|
||||
while (index < buffer.Length)
|
||||
|
|
@ -50,6 +61,7 @@ namespace Server.Network
|
|||
buffer[index] = 0;
|
||||
index += chunkLength;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue