diff --git a/internal/benchmarks/micro/micro_test.go b/internal/benchmarks/micro/micro_test.go index dd967448b..cbfb2449c 100644 --- a/internal/benchmarks/micro/micro_test.go +++ b/internal/benchmarks/micro/micro_test.go @@ -67,6 +67,14 @@ func BenchmarkEmptyMessage(b *testing.B) { } }) }) + b.Run("New", func(b *testing.B) { + mt := (&emptypb.Empty{}).ProtoReflect().Type() + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + mt.New() + } + }) + }) } // BenchmarkRepeatedInt32 tests a message containing 500 non-packed repeated int32s. diff --git a/internal/impl/message.go b/internal/impl/message.go index 3945ab2ed..4f5fb67a0 100644 --- a/internal/impl/message.go +++ b/internal/impl/message.go @@ -218,7 +218,11 @@ fieldLoop: } func (mi *MessageInfo) New() protoreflect.Message { - return mi.MessageOf(reflect.New(mi.GoReflectType.Elem()).Interface()) + m := reflect.New(mi.GoReflectType.Elem()).Interface() + if r, ok := m.(protoreflect.ProtoMessage); ok { + return r.ProtoReflect() + } + return mi.MessageOf(m) } func (mi *MessageInfo) Zero() protoreflect.Message { return mi.MessageOf(reflect.Zero(mi.GoReflectType).Interface())