Reading repeated numeric fields through List.Get allocates once per element
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- go
- Lĩnh vực
- performance
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Go
- Star
- 691
- Fork
- 19
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bufbuild/hyperpb-go
-
# Decoding a message-valued map entry with an omitted value failsCó thể đã có người làm @MaxWang007 đã nhận 6 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
bufbuild/hyperpb-go#50 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
bufbuild/hyperpb-go#47 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
bufbuild/hyperpb-go#30 · 1 bình luận · 1 reaction ·
Tất cả issue của bufbuild/hyperpb-go
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:other issue-rating: 🦞 diamond lobster no-stale P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openclaw/crabbox#3249 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
ec2-subnet, security-group and internet-gateway skip all resources when one is deleted during the scanCó thể đã có người làm @toabctl đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
gruntwork-io/cloud-nuke#1208 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
snowflakedb/gosnowflake#1872 ·