planetscale / planetscale/vtprotobuf
Support pooling repeated fields
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.1k
- Forks
- 112
- PR merge metrics
- No merged PRs in 30d
Description
As far as I can tell single fields are pooled correctly but repeated fields are not. Using the following proto:
message Parent {
option (vtproto.mempool) = true;
repeated Child children = 1;
Child one = 2;
}
message Child {
option (vtproto.mempool) = true;
uint32 field = 1;
}
I can see the the ResetVT and UnmarshalVT methods correctly handle the "one" field but not the "children" field.
func (m *Parent) ResetVT() {
for _, mm := range m.Children {
mm.ResetVT() // does not return the slice pointers to the pool
}
m.One.ReturnToVTPool() // correctly returns this pointer to the pool
m.Reset()
}
func (m *Parent) UnmarshalVT(dAtA []byte) error {
...
switch fieldNum {
case 1:
...
if len(m.Children) == cap(m.Children) {
m.Children = append(m.Children, &Child{}) // allocates new object for slice
} else {
m.Children = m.Children[:len(m.Children)+1]
if m.Children[len(m.Children)-1] == nil {
m.Children[len(m.Children)-1] = &Child{} // allocates new object for slice
}
}
...
case 2:
...
if m.One == nil {
m.One = ChildFromVTPool() // correctly pulls from pool
}
...
Is there a way to do this that I'm not seeing?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the generated Parent.ResetVT and Parent.UnmarshalVT paths shown in the report, then trace the generator entry point that produces repeated-message handling. Done means repeated Child values are returned to and obtained from the pool like the one field, with coverage for the provided proto example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100