From 8f61b0e180665ac1cebb9b657185fc490e3bc345 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Thu, 30 Nov 2023 20:30:05 +0800 Subject: [PATCH] Revert "chore: Shrink allocator pool range" This reverts commit 3c088b33a234395e2fdd5cb7c99fb8689b549976. --- common/pool/alloc.go | 85 +++++++++++++++++++++++++-------------- common/pool/alloc_test.go | 4 +- 2 files changed, 57 insertions(+), 32 deletions(-) diff --git a/common/pool/alloc.go b/common/pool/alloc.go index 0a629403..ee3fa1a1 100644 --- a/common/pool/alloc.go +++ b/common/pool/alloc.go @@ -12,7 +12,7 @@ var defaultAllocator = NewAllocator() // Allocator for incoming frames, optimized to prevent overwriting after zeroing type Allocator struct { - buffers [11]sync.Pool + buffers [17]sync.Pool } // NewAllocator initiates a []byte allocator for frames less than 65536 bytes, @@ -20,7 +20,13 @@ type Allocator struct { // no more than 50%. func NewAllocator() *Allocator { return &Allocator{ - buffers: [...]sync.Pool{ // 64B -> 64K + buffers: [...]sync.Pool{ // 1B -> 64K + {New: func() any { return new([1]byte) }}, + {New: func() any { return new([1 << 1]byte) }}, + {New: func() any { return new([1 << 2]byte) }}, + {New: func() any { return new([1 << 3]byte) }}, + {New: func() any { return new([1 << 4]byte) }}, + {New: func() any { return new([1 << 5]byte) }}, {New: func() any { return new([1 << 6]byte) }}, {New: func() any { return new([1 << 7]byte) }}, {New: func() any { return new([1 << 8]byte) }}, @@ -46,38 +52,46 @@ func (alloc *Allocator) Get(size int) []byte { case size > 65536: return make([]byte, size) default: - var index uint16 - if size > 64 { - index = msb(size) - if size != 1<