Skip to content

Commit 41a0a0c

Browse files
committed
protobuf: add vtproto as a supplemental marshaler
vtproto is an extra protobuf compiler that generates special methods suffixed with `VT` that create typed and unrolled marshal and unmarshal functions similar to gogo that can be used for performance sensitive code. These extensions are optional for code to use but buildkit uses them. A codec is also included to utilize vtproto for grpc code. If the package `github.com/moby/buildkit/util/grpcutil/encoding/proto` is imported then vtproto will be used if it exists and otherwise it will use the standard marshaling and unmarshaling methods. This codec has an important difference from the default codec. The default codec will always reset messages before unmarshaling. In most cases, this is unnecessary and is only relevant for `RecvMsg` on streams. In most cases, if we are passing in an existing message to this method, we want to reuse the buffers. This codec will always merge the message when unmarshaling instead of resetting the input message. Signed-off-by: Jonathan A. Sternberg <[email protected]>
1 parent 7fc8434 commit 41a0a0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+54244
-152
lines changed

api/services/control/control_bench_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
digest "github.com/opencontainers/go-digest"
88
"github.com/stretchr/testify/require"
9-
"google.golang.org/protobuf/proto"
9+
proto "google.golang.org/protobuf/proto"
1010
"google.golang.org/protobuf/types/known/timestamppb"
1111
)
1212

@@ -17,7 +17,7 @@ func BenchmarkMarshalVertex(b *testing.B) {
1717
v := sampleVertex()
1818
for i := 0; i < b.N; i++ {
1919
var err error
20-
Buf, err = proto.Marshal(v)
20+
Buf, err = v.MarshalVT()
2121
require.NoError(b, err)
2222
}
2323
}
@@ -26,7 +26,7 @@ func BenchmarkMarshalVertexStatus(b *testing.B) {
2626
v := sampleVertexStatus()
2727
for i := 0; i < b.N; i++ {
2828
var err error
29-
Buf, err = proto.Marshal(v)
29+
Buf, err = v.MarshalVT()
3030
require.NoError(b, err)
3131
}
3232
}
@@ -35,7 +35,7 @@ func BenchmarkMarshalVertexLog(b *testing.B) {
3535
v := sampleVertexLog()
3636
for i := 0; i < b.N; i++ {
3737
var err error
38-
Buf, err = proto.Marshal(v)
38+
Buf, err = v.MarshalVT()
3939
require.NoError(b, err)
4040
}
4141
}
@@ -48,7 +48,7 @@ func BenchmarkUnmarshalVertex(b *testing.B) {
4848
require.NoError(b, err)
4949

5050
for i := 0; i < b.N; i++ {
51-
err := proto.Unmarshal(buf, &VertexOutput)
51+
err := VertexOutput.UnmarshalVT(buf)
5252
require.NoError(b, err)
5353
}
5454
}
@@ -61,7 +61,7 @@ func BenchmarkUnmarshalVertexStatus(b *testing.B) {
6161
require.NoError(b, err)
6262

6363
for i := 0; i < b.N; i++ {
64-
err := proto.Unmarshal(buf, &VertexStatusOutput)
64+
err := VertexStatusOutput.UnmarshalVT(buf)
6565
require.NoError(b, err)
6666
}
6767
}
@@ -74,7 +74,7 @@ func BenchmarkUnmarshalVertexLog(b *testing.B) {
7474
require.NoError(b, err)
7575

7676
for i := 0; i < b.N; i++ {
77-
err := proto.Unmarshal(buf, &VertexLogOutput)
77+
err := VertexLogOutput.UnmarshalVT(buf)
7878
require.NoError(b, err)
7979
}
8080
}

0 commit comments

Comments
 (0)