Skip to content

Commit

Permalink
protobuf: add vtproto as a supplemental marshaler
Browse files Browse the repository at this point in the history
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 <jonathan.sternberg@docker.com>
  • Loading branch information
jsternberg committed Oct 3, 2024
1 parent ca72046 commit 39bdef6
Show file tree
Hide file tree
Showing 96 changed files with 49,184 additions and 175 deletions.
14 changes: 7 additions & 7 deletions api/services/control/control_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

digest "github.com/opencontainers/go-digest"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
proto "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)

Expand All @@ -17,7 +17,7 @@ func BenchmarkMarshalVertex(b *testing.B) {
v := sampleVertex()
for i := 0; i < b.N; i++ {
var err error
Buf, err = proto.Marshal(v)
Buf, err = v.MarshalVT()
require.NoError(b, err)
}
}
Expand All @@ -26,7 +26,7 @@ func BenchmarkMarshalVertexStatus(b *testing.B) {
v := sampleVertexStatus()
for i := 0; i < b.N; i++ {
var err error
Buf, err = proto.Marshal(v)
Buf, err = v.MarshalVT()
require.NoError(b, err)
}
}
Expand All @@ -35,7 +35,7 @@ func BenchmarkMarshalVertexLog(b *testing.B) {
v := sampleVertexLog()
for i := 0; i < b.N; i++ {
var err error
Buf, err = proto.Marshal(v)
Buf, err = v.MarshalVT()
require.NoError(b, err)
}
}
Expand All @@ -48,7 +48,7 @@ func BenchmarkUnmarshalVertex(b *testing.B) {
require.NoError(b, err)

for i := 0; i < b.N; i++ {
err := proto.Unmarshal(buf, &VertexOutput)
err := VertexOutput.UnmarshalVT(buf)
require.NoError(b, err)
}
}
Expand All @@ -61,7 +61,7 @@ func BenchmarkUnmarshalVertexStatus(b *testing.B) {
require.NoError(b, err)

for i := 0; i < b.N; i++ {
err := proto.Unmarshal(buf, &VertexStatusOutput)
err := VertexStatusOutput.UnmarshalVT(buf)
require.NoError(b, err)
}
}
Expand All @@ -74,7 +74,7 @@ func BenchmarkUnmarshalVertexLog(b *testing.B) {
require.NoError(b, err)

for i := 0; i < b.N; i++ {
err := proto.Unmarshal(buf, &VertexLogOutput)
err := VertexLogOutput.UnmarshalVT(buf)
require.NoError(b, err)
}
}
Expand Down
Loading

0 comments on commit 39bdef6

Please sign in to comment.