You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Whenever a BoundField is written a new TypeAdapterRuntimeTypeWrapper is constructed. As far as I can tell the TypeAdapterRuntimeTypeWrapper could just as well be constructed as a final variable outside of the write method. When re-using Gson instances this will reduce the total amount of memory allocated during serialization.
The text was updated successfully, but these errors were encountered:
Thanks! This looks like a good suggestion, do you want to create a pull request for this?
I assume if serialized == false there would also be no need to create the TypeAdapterRuntimeTypeWrapper then if it is not used anyways.
I wasn't completely convinced at first: if we construct the TypeAdapterRuntimeTypeWrapper outside the anonymous BoundField then we save having to construct it inside, but on the other hand we have a bit more memory being used all the time versus just inside BoundField.write. But actually I see that there are three local variables captured in createBoundField just so that they can be used in this one line: typeAdapter, context, and fieldType. That means three hidden fields in the anonymous subclass. If we construct the final TypeAdapter just once then that is just one hidden field, assuming we also use it in the readIntoArray and readIntoField methods. So I think the extra memory is pretty small.
In short, thank you for the idea, and I agree with @Marcono1234 that a PR would be welcome.
Problem solved by the feature
Reduced memory allocation when serializing data.
Feature description
Whenever a BoundField is written a new TypeAdapterRuntimeTypeWrapper is constructed. As far as I can tell the TypeAdapterRuntimeTypeWrapper could just as well be constructed as a final variable outside of the write method. When re-using Gson instances this will reduce the total amount of memory allocated during serialization.
The text was updated successfully, but these errors were encountered: