File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -48,16 +48,20 @@ func (c *codecV2) Marshal(v any) (data mem.BufferSlice, err error) {
4848 }
4949
5050 size := proto .Size (vv )
51+ // proto.Size caches the size, enabling UseCachedSize
52+ // lets us reuse that value instead of recomputing it during marshal.
53+ marshalOptions := proto.MarshalOptions {UseCachedSize : true }
54+
5155 if mem .IsBelowBufferPoolingThreshold (size ) {
52- buf , err := proto. MarshalOptions { UseCachedSize : true } .Marshal (vv )
56+ buf , err := marshalOptions .Marshal (vv )
5357 if err != nil {
5458 return nil , err
5559 }
5660 data = append (data , mem .SliceBuffer (buf ))
5761 } else {
5862 pool := mem .DefaultBufferPool ()
5963 buf := pool .Get (size )
60- if _ , err := (proto. MarshalOptions { UseCachedSize : true }) .MarshalAppend ((* buf )[:0 ], vv ); err != nil {
64+ if _ , err := marshalOptions .MarshalAppend ((* buf )[:0 ], vv ); err != nil {
6165 pool .Put (buf )
6266 return nil , err
6367 }
You can’t perform that action at this time.
0 commit comments