Optimize Memory Usage by Interning Frequently Occurring Strings in JSON#1585
Conversation
|
Is it possible to configure GSON to use |
Unfortunately, no, GSON doesn't support it. And actually, we don't want every string to be interned because many fields have arbitrary data (not like enum values) and it doesn't make sense to intern value that exists only once, this will degrade performance. Ideal solution would be to choose which fields we want to intern, for example, by marking them with annotation like But it's not possible without patching GSON SDK and I'm not sure if it makes sense to do it now given our pans on changing parsing mechanism. |
It's should be possible. Serialization process is controlled by code generated with mapbox fork of auto value gson library - https://github.com/mapbox/auto-value-gson, I think we should be able to add support of |
https://mapbox.atlassian.net/browse/NAVAND-3254
In the directions response format, there are string elements that can have a limited number of values but frequently occur in the JSON response. Some of them are:
IntersectionLanes.indications(),IntersectionLanes.validIndication(),StepManeuver.type(), andStepManeuver.modifier(). The GSON parser does not support string interning, which leads to new string allocations every time. Consequently, the parsed route object contains many duplicate strings. In this PR, we introduce custom TypeAdapters that intern selected strings to save memory.Some analysis for
IntersectionLanesobjects: