planetscale / planetscale/vtprotobuf

Marshal to multiple buffers

Open
#151 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
1.1k
Forks
112
PR merge metrics
No merged PRs in 30d

Description

In my use case, I am sending messages that have many repeated fields (tens or hundreds of thousands). This is the proto if it is relevant.

Ideally we would split this up at the application level, but for various reasons we can't do this.

Instead, it would be nice if we could marshal to multiple slices, rather than one giant one, using mem.BufferSlice.

This could look something like this:

mem.BufferSlice{
  everythingSerializedBesidesResources,
  resource1,
  resource2,
  resource3,
   ...
}

A specialization of this is that in our particular use case, the repeated field is an anypb.Any -- this is preserialized into []byte. We are already caching this serialization, so it would be ideal to not copy that at all and instead just reference the slice in the mem.BufferSlice. That would then look like...

mem.BufferSlice{
  everythingSerializedBesidesResources,
  resource1BesidesBytesValue, resource1BytesValue,
  resource2BesidesBytesValue, resource2BytesValue,
   ...
}

I put together a POC doing this and saw pretty promising results:

benchmark            ns/op 
golang-protobuf      11116     
vtprotobuf           2858      
hand-optimized       125       

(code is here, its not correct but should be correct-enough to get a broad idea of the performance. It could be faster, simpler, and more correct).

TBH I mostly think this is likely out of scope for this library and pretty usage-specific, but wanted to raise it in case others were interested. I am not really sure how this would even be exposed in the API. At minimum we would need a new marshal interface that returns mem.BufferSlice and some way to indicate when/how to split messages.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no vtprotobuf files or tests; start by reviewing the linked POC commit and the Envoy discovery.proto repeated field. Clarify the marshal API and BufferSlice ownership requirements, then define acceptance around generated output, cached byte slices, correctness, and benchmarks before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.