-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize wire.Uint.save() to make only 1 Write() call.
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
- Loading branch information
1 parent
f97dd13
commit 905d769
Showing
6 changed files
with
56 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 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) | ||
} | ||
} |