mirror of
https://github.com/hanzoai/visor.git
synced 2026-09-24 17:04:14 +00:00
Earlier wire.Uint.save() could make up to 10 Write() calls depending on how large the Uint being marshaled was. Write() is an interface method call, so this avoids the dynamic dispatch overhead. Furthermore, compressio's Write implementations themselves do a bunch of fixed work per call and invoke more interface functions. Increased the scratch buffer in the wire.Writer to accommodate 10 bytes. The wire.Uint can be marshaled into at most 10 bytes. Before: goos: linux goarch: amd64 pkg: pkg/state/wire/wire cpu: AMD EPYC 7B12 BenchmarkUintSave BenchmarkUintSave-24 37557860 31.13 ns/op 0 B/op 0 allocs/op After: goos: linux goarch: amd64 pkg: pkg/state/wire/wire cpu: AMD EPYC 7B12 BenchmarkUintSave BenchmarkUintSave-24 129611625 9.274 ns/op 0 B/op 0 allocs/op PiperOrigin-RevId: 672679703
33 lines
1016 B
Go
33 lines
1016 B
Go
// Copyright 2024 The gVisor Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package wire
|
|
|
|
import (
|
|
"bufio"
|
|
"io"
|
|
"testing"
|
|
)
|
|
|
|
// BenchmarkUintSave benchmarks saving a Uint. This benchmark is important
|
|
// because almost all types in this package boil down to Uints. So
|
|
// Uint.save() performance is critical for checkpoint performance.
|
|
func BenchmarkUintSave(b *testing.B) {
|
|
w := Writer{Writer: bufio.NewWriter(io.Discard)}
|
|
n := Uint(0xdeadbeef)
|
|
for i := 0; i < b.N; i++ {
|
|
n.save(&w)
|
|
}
|
|
}
|