Skip to content

Reduce allocations in protoencoding.ReparseExtensions#4493

Open
pkwarren wants to merge 1 commit intomainfrom
pkw/reparse-extensions-allocs
Open

Reduce allocations in protoencoding.ReparseExtensions#4493
pkwarren wants to merge 1 commit intomainfrom
pkw/reparse-extensions-allocs

Conversation

@pkwarren
Copy link
Copy Markdown
Member

The protoencoding.ReparseExtensions method is showing up in memory profiles as a large source of allocations. Update the method to add a per-call cache to prevent allocations when revisiting the same types.

The protoencoding.ReparseExtensions method is showing up in memory
profiles as a large source of allocations. Update the method to add a
per-call cache to prevent allocations when revisiting the same types.
@pkwarren pkwarren requested a review from jhump April 20, 2026 23:48
@github-actions
Copy link
Copy Markdown
Contributor

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedApr 20, 2026, 11:49 PM

// BenchmarkReparseExtensions_Synthetic exercises a hand-built FileDescriptorProto
// that mirrors the shape of a validate-annotated proto file with an unrecognized
// extension to force the reparse path.
func BenchmarkReparseExtensions_Synthetic(b *testing.B) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goos: darwin
goarch: arm64
pkg: github.com/bufbuild/buf/private/pkg/protoencoding
cpu: Apple M4 Pro
                               │ /tmp/reparse_old.txt │        /tmp/reparse_new.txt         │
                               │        sec/op        │   sec/op     vs base                │
ReparseExtensions_Synthetic-12            3.508m ± 1%   3.611m ± 1%   +2.92% (p=0.000 n=10)
ReparseExtensions_RealWorld-12            3.517m ± 1%   2.204m ± 0%  -37.33% (p=0.000 n=10)
geomean                                   3.513m        2.821m       -19.69%

                               │ /tmp/reparse_old.txt │         /tmp/reparse_new.txt         │
                               │         B/op         │     B/op      vs base                │
ReparseExtensions_Synthetic-12           3.629Mi ± 0%   3.568Mi ± 0%   -1.70% (p=0.000 n=10)
ReparseExtensions_RealWorld-12           4.635Mi ± 0%   2.992Mi ± 0%  -35.45% (p=0.000 n=10)
geomean                                  4.101Mi        3.267Mi       -20.34%

                               │ /tmp/reparse_old.txt │        /tmp/reparse_new.txt         │
                               │      allocs/op       │  allocs/op   vs base                │
ReparseExtensions_Synthetic-12            57.63k ± 0%   53.55k ± 0%   -7.09% (p=0.000 n=10)
ReparseExtensions_RealWorld-12           111.35k ± 0%   61.32k ± 0%  -44.93% (p=0.000 n=10)
geomean                                   80.11k        57.30k       -28.47%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant