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

BoundField.write memory optimization #2325

Merged
merged 2 commits into from
Feb 28, 2023
Merged

Conversation

sembseth
Copy link
Contributor

@sembseth sembseth commented Feb 25, 2023

Declare and initialize the type adapter used for writing BoundFields outside of the anonymous class to ensure that a new TypeAdapterRuntimeTypeWrapper is not constructed each time a BoundField is written. This type adapter is only initialized if the BoundField will be used for serialization.

See #2321 for more details.

Closes #2321.

Declare and initialize the type adapter used for writing BoundFields outside of the anonymous class to ensure that a new TypeAdapterRuntimeTypeWrapper is not constructed each time a BoundField is written. This type adapter is only initialized if the BoundField will be used for serialization.
@Marcono1234
Copy link
Collaborator

Marcono1234 commented Feb 25, 2023

Thanks! Could you for convenience please edit the description of this pull request to include "Closes #2321"? GitHub recognizes certain keywords and automatically closes linked issues then.

(Alternatively the maintainers could manually link the pull request and the issue.)

@eamonnmcmanus
Copy link
Member

Thanks! Could you for convenience please edit the description of this pull request to include "Closes #2321"?

I took the liberty of updating the PR description.

: new TypeAdapterRuntimeTypeWrapper<>(context, typeAdapter, fieldType.getType());
} else {
// The field will never be serialized, skip the unnecessary type adapter construction
writeTypeAdapter = null;
Copy link
Member

Choose a reason for hiding this comment

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

While this is correct, I think it's likely to confuse nullness-analysis tools. It's just as easy to set this to typeAdapter here, which should confuse them less.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point, updated now.

Copy link
Member

@eamonnmcmanus eamonnmcmanus left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks again for doing this!

@eamonnmcmanus eamonnmcmanus merged commit 105f28f into google:master Feb 28, 2023
tibor-universe pushed a commit to getuniverse/gson that referenced this pull request Sep 14, 2024
* BoundField.write memory optimization

Declare and initialize the type adapter used for writing BoundFields outside of the anonymous class to ensure that a new TypeAdapterRuntimeTypeWrapper is not constructed each time a BoundField is written. This type adapter is only initialized if the BoundField will be used for serialization.

* Avoid confusing nullness-analysis tools
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.

ReflectiveTypeAdapterFactory.BoundField.write memory overhead
3 participants