forked from TrueCloudLab/frostfs-node
[#285] blobonicza: Optimize upperPowerOfTwo()
The real reason is this: ``` pkg/local_object_storage/blobovnicza/sizes.go:36:69 revive empty-block: this block is empty, you can remove it ``` Didn't want to make this function longer or to add `nolint`, thus this change. To justify: ``` UpperBound/size=1-8 0.4924n ± 1% 0.2472n ± 2% -49.80% (p=0.000 n=10) UpperBound/size=1023-8 0.4936n ± 3% 0.2442n ± 1% -50.52% (p=0.000 n=10) UpperBound/size=66560-8 0.8201n ± 2% 0.2436n ± 1% -70.29% (p=0.000 n=10) UpperBound/size=41943040-8 6.6900n ± 5% 0.2432n ± 0% -96.36% (p=0.000 n=10) geomean 1.075n 0.2446n -77.24% ``` Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
dfe4ada838
commit
1f4061c0e2
2 changed files with 16 additions and 4 deletions
|
@ -3,6 +3,7 @@ package blobovnicza
|
|||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math/bits"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
@ -31,11 +32,11 @@ func bucketForSize(sz uint64) []byte {
|
|||
return bucketKeyFromBounds(upperPowerOfTwo(sz))
|
||||
}
|
||||
|
||||
func upperPowerOfTwo(v uint64) (upperBound uint64) {
|
||||
for upperBound = firstBucketBound; upperBound < v; upperBound *= 2 {
|
||||
func upperPowerOfTwo(v uint64) uint64 {
|
||||
if v <= firstBucketBound {
|
||||
return firstBucketBound
|
||||
}
|
||||
|
||||
return
|
||||
return 1 << bits.Len64(v-1)
|
||||
}
|
||||
|
||||
func (b *Blobovnicza) incSize(sz uint64) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package blobovnicza
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -36,3 +37,13 @@ func TestSizes(t *testing.T) {
|
|||
require.Equal(t, bucketKeyFromBounds(item.upperBound), bucketForSize(item.sz))
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkUpperBound(b *testing.B) {
|
||||
for _, size := range []uint64{1, 1023, 65 * 1024, 40 * 1024 * 1024} {
|
||||
b.Run(fmt.Sprintf("size=%d", size), func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = upperPowerOfTwo(size)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue