Skip to content

Conversation

ejona86
Copy link
Member

@ejona86 ejona86 commented Aug 14, 2025

Modifying existing Attributes was virtually guaranteed to allocate within build(), just because base was not considered for the new map size. Discard was also allocation-heavy because it often created a new map. Using a regular copy-on-write approach is enough to avoid the unnecessary allocations in both cases.

This was noticed in a profile that included xds's
AddressFilter.setPathFilter(), where Attributes.Builder.build() allocated 6x the memory of Attributes.Builder.data().

b/435208946#comment41

Modifying existing Attributes was virtually guaranteed to allocate
within build(), just because `base` was not considered for the new map
size. Discard was also allocation-heavy because it often created a new
map. Using a regular copy-on-write approach is enough to avoid the
unnecessary allocations in both cases.

This was noticed in a profile that included xds's
AddressFilter.setPathFilter(), where Attributes.Builder.build()
allocated 6x the memory of Attributes.Builder.data().

b/435208946#comment41
@ejona86 ejona86 requested a review from AgraVator August 14, 2025 14:39
@ejona86 ejona86 merged commit 695014a into grpc:master Aug 26, 2025
16 checks passed
@ejona86 ejona86 deleted the attributes-reducedalloc branch August 26, 2025 13:53
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants