Reading repeated numeric fields through List.Get allocates once per element
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- go
- Área
- performance
Línea de trabajo
Start with the reproducer, which uses testing.AllocsPerRun around the loop calling list.Get(i).Uint() on a packed uint64 field decoded by hyperpb. Read how the list's Get method boxes each element into a protoreflect.Value, since that is where the per-element allocation most likely happens. Save the reproducer as a benchmark or test. Done when the scan reports allocs/scan=0 and the sum is unchanged.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
Scanning an already-decoded packed uint64 field through protoreflect.List.Get(i).Uint() allocates one heap object per element in the reproducer below. The allocations occur during the scan, after unmarshalling and retrieving the list. In a scan of one million elements, they add about 8 MB of heap allocation.
Versions / platform
buf.build/go/hyperpbv0.1.3google.golang.org/protobufv1.36.9- Go 1.27.4 on
darwin/arm64(Apple M1)
Reproducer
Save as main.go in an empty directory and run the following commands.
go mod init repro
go get buf.build/go/[email protected] google.golang.org/[email protected]
go run .
package main
import (
"fmt"
"testing"
"buf.build/go/hyperpb"
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/types/descriptorpb"
)
func main() {
const count = 256
file, err := protodesc.NewFile(&descriptorpb.FileDescriptorProto{
Name: proto.String("repro.proto"),
Syntax: proto.String("proto3"),
MessageType: []*descriptorpb.DescriptorProto{{
Name: proto.String("Sample"),
Field: []*descriptorpb.FieldDescriptorProto{{
Name: proto.String("values"),
Number: proto.Int32(1),
Label: descriptorpb.FieldDescriptorProto_LABEL_REPEATED.Enum(),
Type: descriptorpb.FieldDescriptorProto_TYPE_UINT64.Enum(),
}},
}},
}, nil)
if err != nil {
panic(err)
}
desc := file.Messages().Get(0)
packed := make([]byte, 0, 2*count)
for i := range count {
packed = protowire.AppendVarint(packed, uint64(256+i))
}
payload := protowire.AppendTag(nil, 1, protowire.BytesType)
payload = protowire.AppendBytes(payload, packed)
shared := new(hyperpb.Shared)
defer shared.Free()
msg := shared.NewMessage(hyperpb.CompileMessageDescriptor(desc))
if err := msg.Unmarshal(payload); err != nil {
panic(err)
}
list := msg.ProtoReflect().Get(desc.Fields().ByNumber(1)).List()
if list.Len() != count {
panic("unexpected list length")
}
var sum uint64
allocs := testing.AllocsPerRun(10, func() {
sum = 0
for i := range count {
sum += list.Get(i).Uint()
}
})
fmt.Printf("sum=%d allocs/scan=%.0f\n", sum, allocs)
}
Observed
sum=98176 allocs/scan=256
Expected
The scan returns the same sum with zero heap allocations.
sum=98176 allocs/scan=0
- Lenguaje dominante
- Go
- Estrellas
- 691
- Forks
- 19
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de bufbuild/hyperpb-go
-
# Decoding a message-valued map entry with an omitted value failsPosiblemente ocupada @MaxWang007 la tomó hace 6 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
bufbuild/hyperpb-go#50 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
bufbuild/hyperpb-go#47 · 1 comentario ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
bufbuild/hyperpb-go#30 · 1 comentario · 1 reacción ·
Todos los issues de bufbuild/hyperpb-go
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:other issue-rating: 🦞 diamond lobster no-stale P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
openclaw/crabbox#3249 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
ec2-subnet, security-group and internet-gateway skip all resources when one is deleted during the scanPosiblemente ocupada @toabctl la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
gruntwork-io/cloud-nuke#1208 ·
Los mantenedores suelen responder en 5 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
snowflakedb/gosnowflake#1872 ·