Reduce allocations in protoencoding.ReparseExtensions#4493
Open
Reduce allocations in protoencoding.ReparseExtensions#4493
Conversation
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.
Contributor
|
The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).
|
pkwarren
commented
Apr 20, 2026
| // 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) { |
Member
Author
There was a problem hiding this comment.
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%
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.