Skip to content

Conversation

@granulatedekel
Copy link

@granulatedekel granulatedekel commented Nov 18, 2024

refactor all usages of the Gson object to use a singleton instance - sparing costly initialization, which has resulted in major performance implications for our clients.

this is a known optimization as Gson instances are stateless and thread-safe ("Gson instances are Thread-safe so you can reuse them freely across multiple threads" https://www.javadoc.io/doc/com.google.code.gson/gson/2.9.0/com.google.gson/com/google/gson/Gson.html)

https://stackoverflow.com/questions/31432758/should-i-reuse-one-instance-of-gson-or-create-new-ones-on-demand
https://stackoverflow.com/questions/10380835/is-it-ok-to-use-gson-instance-as-a-static-field-in-a-model-bean-reuse

tests and lint pass.

in addition consolidated fromJson declarations to a single top level one in Utils to avoid code redundancy.

@YoniKF
Copy link

YoniKF commented Dec 12, 2024

Hi @brock-statsig, @weihao-statsig, @xinlili-statsig, and team,
Is this change something you are willing to accept into the repo?
We (Intel Granulate) have observed this inefficiency on several services of our clients and think that it makes sense to fix it at the source.

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.

2 participants