From 3042e377679844d1a8acdd3671f07425c9ff4a44 Mon Sep 17 00:00:00 2001 From: Balaji Jinnah Date: Fri, 26 Jun 2020 21:34:43 +0530 Subject: [PATCH] pre allocate cache key for the block cache and the bloom filter cache (#1371) Signed-off-by: Tiger --- table/table.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/table/table.go b/table/table.go index 8b88a69a9..e66fa63d0 100644 --- a/table/table.go +++ b/table/table.go @@ -596,11 +596,13 @@ func (t *Table) block(idx int) (*block, error) { // bfCacheKey returns the cache key for bloom filter. func (t *Table) bfCacheKey() []byte { y.AssertTrue(t.id < math.MaxUint32) - buf := make([]byte, 4) - binary.BigEndian.PutUint32(buf, uint32(t.id)) - + buf := make([]byte, 6) // Without the "bf" prefix, we will have conflict with the blockCacheKey. - return append([]byte("bf"), buf...) + buf[0] = 'b' + buf[1] = 'f' + + binary.BigEndian.PutUint32(buf[2:], uint32(t.id)) + return buf } func (t *Table) blockCacheKey(idx int) []byte { @@ -617,10 +619,12 @@ func (t *Table) blockCacheKey(idx int) []byte { // blockOffsetsCacheKey returns the cache key for block offsets. func (t *Table) blockOffsetsCacheKey() []byte { y.AssertTrue(t.id < math.MaxUint32) - buf := make([]byte, 4, 6) - binary.BigEndian.PutUint32(buf, uint32(t.id)) + buf := make([]byte, 6) + buf[0] = 'b' + buf[1] = 'o' - return append([]byte("bo"), buf...) + binary.BigEndian.PutUint32(buf[2:], uint32(t.id)) + return buf } // EstimatedSize returns the total size of key-values stored in this table (including the