open-feature / open-feature/java-sdk

Cache merged context

Open
#1,588 0 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
128
Forks
61
Avg merge
5h 57m
Merged PRs (30d)
26

Description

Currently, the OpenFeatureClient.evaluateFlag() method performs a complete context merge on every flag evaluation by calling mergeEvaluationContext(), which merges all four context levels from scratch: API context (global), Transaction context, Client context, Invocation context (evaluation-specific)

Problem: This bottom-up approach is inefficient because:
* API, transaction, and client contexts change infrequently compared to evaluation frequency
* Each evaluation recreates the same merged context for the stable upper levels
* Unnecessary object allocation and computation occurs on every evaluation

Proposed Solution: Implement a top-down context propagation system:
* API level: When API context changes, propagate to transaction level
* Transaction level: When transaction context changes, propagate to client level
* Client level: When client context changes, create pre-merged context (API + Transaction + Client)
* Evaluation: Only merge the pre-computed context with the invocation context

Benefits:
* Reduces object churn and GC pressure and improves performance in high-evaluation scenarios
* Enables better performance scaling for applications with many flag evaluations

The documentation should recommend setting contexts before creating clients to maximize caching benefits.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.