github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/lsmkv/compactor_map_reusable_pairs.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package lsmkv 13 14 // reusableMapPairs is not thread-safe and intended for usage from a single 15 // thread. The caller is resoponsible for initializing each element themselves, 16 // the Resize functions will only set the size. If the size is reduced, this 17 // will only truncate elements, but will not reset values. 18 type reusableMapPairs struct { 19 left []MapPair 20 right []MapPair 21 } 22 23 func newReusableMapPairs() *reusableMapPairs { 24 return &reusableMapPairs{} 25 } 26 27 func (rmp *reusableMapPairs) ResizeLeft(size int) { 28 if cap(rmp.left) >= size { 29 rmp.left = rmp.left[:size] 30 } else { 31 // The 25% overhead for the capacity was chosen because we saw a lot 32 // re-allocations during testing with just a few elements more than before. 33 // This is something that really depends on the user's usage pattern, but 34 // in the test scenarios based on the 35 // weaviate-chaos-engineering/apps/importer-no-vector-index test script a 36 // simple 25% overhead reduced the resizing needs to almost zero. 37 rmp.left = make([]MapPair, size, int(float64(size)*1.25)) 38 } 39 } 40 41 func (rmp *reusableMapPairs) ResizeRight(size int) { 42 if cap(rmp.right) >= size { 43 rmp.right = rmp.right[:size] 44 } else { 45 // The 25% overhead for the capacity was chosen because we saw a lot 46 // re-allocations during testing with just a few elements more than before. 47 // This is something that really depends on the user's usage pattern, but 48 // in the test scenarios based on the 49 // weaviate-chaos-engineering/apps/importer-no-vector-index test script a 50 // simple 25% overhead reduced the resizing needs to almost zero. 51 rmp.right = make([]MapPair, size, int(float64(size)*1.25)) 52 } 53 }