-
Notifications
You must be signed in to change notification settings - Fork 56
Description
We use JSON logic as a core component in our feature flag evaluation engine for flagd, which operates in various programming languages. Thanks for providing and maintaining this library in Java!
During memory profiling, we recognized that JSON logic evaluation appears to cause a suspiciously high number of object and memory allocations, primarily due to frequent use of string format operations. Investigation shows the root cause is the jsonPath property introduced in PR #53, which gets constructed along the evaluation path.
Observed Behavior
Memory profiles from some of our workloads reveal that around 82% of allocated memory can be traced back to String creation with String.format(), mostly attributed to the jsonPath construction logic. The attached flame graph illustrates the breakdown.
Steps to Reproduce
- Run a JSON logic evaluation with a typical rule.
- Monitor object creation and memory allocation (e.g., using a profiler).
- Observe allocations related to string formatting and jsonPath construction.
Expected Behavior
- JSON logic evaluation should minimize object and memory allocations, especially during string formatting and path construction, to avoid unnecessary resource consumption.
Potential Solution Suggestions
- Build jsonPath only when needed for exceptions, not on every evaluation, e.g., in catch blocks, to reduce memory usage and object creation.
- Review and refactor string format and jsonPath operations within evaluation.
- Consider using more efficient string manipulation techniques or object pooling where possible.