Use protowire
in util/proto
helpers #50
Labels
No labels
P0
P1
P2
P3
good first issue
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/frostfs-api-go#50
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
It has almost everything we need https://pkg.go.dev/google.golang.org/protobuf@v1.31.0/encoding/protowire#SizeVarint
And communicates our intentions somewhat more clearly. Also, helps to get rid of all these
<< |
bit trickery.After this we can change
protogen
and, possibly, replaceapi-go
dependency withprotowire
We still have a bunch of opportunities for
protowire.AppendBytes
etc.Let's benchmark and replace if possible.
Ah, ok! But we need take in count that it requires some refactoring for StableMarshaller interface to make it possible to use
AppendBytes
Not necessary:
copy(a, b)
can be replaced withappend(a[:0], b...)
, but let's check whether it is slower.The pull-request #56 demonstrates why using
protowire.Append...
methods is not good idea.All api-defined types must impelement
StableMarshal([]byte) []byte)
method (to implementStableMarshaller
interface)When a primitive numeric type is going to be serialized, these methods are used:
...
As you can see, these methods return the offset.
If we consider the idea of using
StableMarshal
, then we can see that we should allocate a slice with defined length (make([]byte, N
) and then we shift the offset for each internalStableMarshal
invocation (io.Write
behaves in the same way)protowire.Append...
method oblige us to allocate a slice with defined capacity with 0 length (make([]byte, 0, N
). So, when we go down toUInt64Marshal
orInt64Marshal
we need to make these methods return the slice instead the offset. Such refactoring breaksfrostfs-node
because there are methods for protobufs that are generated by protoc plugin.We want to keep the same interface and support backward compability. However, another good idea comes up - we may refactor
StableMarshal
toWrite
and make types implementio.Writer
interface that can be very useful