protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Allow builders to return default instance in Java

Open yuzawa-san opened this issue 1 year ago • 1 comments

rationale: I was investigating allocations during parsing where a lot of empty messages were present and realized that each of these empty messages was a newly allocated instance, when it would be more memory efficient to reuse the default instance each time.

solution: add a default flag to the builder which is invalidated onChange. then conditionally return the default instance if that flag is true.

note: I had to bring back some logic removed in c0d08bdcade9d44698015b85c9c23343ca1319b7 in order for the schema flow to work correctly since it was using toBuilder and expecting a new instance, not the default instance.

yuzawa-san avatar Apr 26 '24 18:04 yuzawa-san

@yuzawa-san Unfortunately, while we like the idea, we can't absorb this change. We've actually attempted this internally and there are currently a bunch of tests that rely on .newBuilder().build() returning unique instances. We'd need to address those first.

googleberg avatar May 10 '24 18:05 googleberg

We triage inactive PRs and issues in order to make it easier to find active work. If this PR should remain active, please add a comment.

This PR is labeled inactive because the last activity was over 90 days ago. This PR will be closed and archived after 14 additional days without activity.

github-actions[bot] avatar Aug 09 '24 10:08 github-actions[bot]

We triage inactive PRs and issues in order to make it easier to find active work. If this PR should remain active or becomes active again, please reopen it.

This PR was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

github-actions[bot] avatar Aug 23 '24 10:08 github-actions[bot]