growthbook / growthbook-sdk-java

The Java SDK for GrowthBook (JVM, Android)
https://docs.growthbook.io/lib/java
MIT License
7 stars 10 forks source link

Add support for setting JSON Feature Object in GBContext builder #76

Closed gaurav-rana closed 1 week ago

gaurav-rana commented 1 week ago

The current GBContext implementation is suboptimal for java backend integrations. We have to create a new GBContext for each request, and because the CustomGbContextBuilder only supports StringType featureJson, we have to pass featureJson as string and it parses the JSON (converting from String to JSONType) for each and every request. This can be avoided by letting the application maintain JSON and set JSON directly.

Flame graph with the current GBContext:

Screenshot 2024-06-25 at 1 53 59 PM

As we can see, around 42% of total CPU is spent inside parsing this JSON for each and every request, this overhead can be clearly avoided by letting the client set the JSON directly instead of string.

After the fix: Screenshot 2024-06-25 at 8 41 37 PM

The stack frames for transformFeatures went away.