Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow builders to return default instance in Java #16655

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yuzawa-san
Copy link
Contributor

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 c0d08bd in order for the schema flow to work correctly since it was using toBuilder and expecting a new instance, not the default instance.

rationale: I was investigating allocations during parsing where a lot of empty messages and realized that each of these empty messages was a new instance, when it would be more 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.
@yuzawa-san yuzawa-san requested a review from a team as a code owner April 26, 2024 18:36
@yuzawa-san yuzawa-san requested review from shaod2 and removed request for a team April 26, 2024 18:36
@shaod2 shaod2 requested a review from googleberg April 26, 2024 18:49
@zhangskz zhangskz added the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Apr 29, 2024
@github-actions github-actions bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Apr 29, 2024
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.

None yet

3 participants