Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
-Fix tons of allocations happening when decompressing packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Cassunshine committed Dec 7, 2023
1 parent cc4c7d2 commit 9cde4ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Buffers;
using ZstdSharp;

namespace Common.Util.Serialization.Compressed;
Expand All @@ -9,7 +10,11 @@ public override void LoadData(Span<byte> data) {
using var decompressor = new Decompressor();

var expectedSize = Decompressor.GetDecompressedSize(data);
var rented = ArrayPool<byte>.Shared.Rent((int)expectedSize);

base.LoadData(decompressor.Unwrap(data)); //TODO - Allocation here...
decompressor.Unwrap(data, rented.AsSpan());
base.LoadData(rented);

ArrayPool<byte>.Shared.Return(rented);
}
}
2 changes: 1 addition & 1 deletion Common/Util/Serialization/VDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public VDataReader(byte[]? data = null) {
dataBuffer = data ?? new byte[256];
}

private void EnsureSize(int size) {
protected void EnsureSize(int size) {
//TODO - replace with single CNPOT instead of while loop.
while (dataBuffer.Length < size) {
var oldBytes = dataBuffer;
Expand Down

0 comments on commit 9cde4ee

Please sign in to comment.