Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/beacon-node/src/network/gossip/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ export class DataTransformSnappy implements DataTransform {
}

// Only after sanity length checks, we can decompress the data
const uncompressedData = Buffer.allocUnsafe(uncompressedDataLength);
// Using Buffer.alloc() instead of Buffer.allocUnsafe() to mitigate high GC pressure observed in some environments
const uncompressedData = Buffer.alloc(uncompressedDataLength);
decoder.decompress_into(data, uncompressedData);
return uncompressedData;
}
Expand All @@ -120,7 +121,8 @@ export class DataTransformSnappy implements DataTransform {
throw Error(`ssz_snappy encoded data length ${data.length} > ${this.maxSizePerMessage}`);
}

const compressedData = Buffer.allocUnsafe(snappyWasm.max_compress_len(data.length));
// Using Buffer.alloc() instead of Buffer.allocUnsafe() to mitigate high GC pressure observed in some environments
const compressedData = Buffer.alloc(snappyWasm.max_compress_len(data.length));
const compressedLen = encoder.compress_into(data, compressedData);
return compressedData.subarray(0, compressedLen);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("network / gossip / snappy", () => {
runsFactor: RUNS_FACTOR,
fn: () => {
for (let i = 0; i < RUNS_FACTOR; i++) {
let out = Buffer.allocUnsafe(snappyWasm.max_compress_len(uncompressed.length));
let out = Buffer.alloc(snappyWasm.max_compress_len(uncompressed.length));
const len = encoder.compress_into(uncompressed, out);
out = out.subarray(0, len);
}
Expand Down Expand Up @@ -108,7 +108,7 @@ describe("network / gossip / snappy", () => {
runsFactor: RUNS_FACTOR,
fn: () => {
for (let i = 0; i < RUNS_FACTOR; i++) {
decoder.decompress_into(compressed, Buffer.allocUnsafe(snappyWasm.decompress_len(compressed)));
decoder.decompress_into(compressed, Buffer.alloc(snappyWasm.decompress_len(compressed)));
}
},
});
Expand Down
Loading