Repository navigation
Conversation
toLdContext called asMap() twice on the evaluation context, and once more on each nested structure of a multi-kind context. Each call returns a new copy of the map, on every flag evaluation. The converter only reads these maps. It now reads them through asUnmodifiableMap(), which OpenFeature SDK 1.16.0 already has, and it reuses the top-level map.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
toLdContextcalledasMap()twice on the evaluation context, and once more on each nested structure of a multi-kind context. Each call returns a new copy of the map, on every flag evaluation.The converter only reads these maps. It now reads them through
asUnmodifiableMap(), which OpenFeature SDK 1.16.0 already has, and it reuses the top-level map.Requirements
Related issues
None.
Describe the solution you've provided
The converter reads the evaluation context and each nested structure through
asUnmodifiableMap(), and passes the top-level map toBuildSingleContextandBuildMultiContext. The converter only reads these maps, so the copies are not necessary.Behavior does not change. Before and after return the same
LDContextfor single-kind, multi-kind, nested-kind and invalid contexts.Describe alternatives you've considered
asMap()result only. That removes one copy but keeps the others.asUnmodifiableMap()removes all of them and is in the lowest supported OpenFeature SDK.ValueConverter, which callsasMap()on attributes whose value is a structure. I left it out to keep this change to the path that every evaluation takes.Additional context
This change adds no tests, because behavior does not change. The existing
ContextConverterTestcovers single-kind, multi-kind, nested-kind and invalid contexts. It passes on JDK 17 with OpenFeature SDK 1.23.0, and with OpenFeature SDK 1.16.0 forced. I did not run it on Java 11 or 19, which CI covers.I used AI in investigating this issue and the perf improvement
Note
Overview
Stops copying evaluation context maps on every flag evaluation by switching
EvaluationContextConverterfromasMap()toasUnmodifiableMap()for the top-level context and nested structures in multi-kind contexts.The converter reuses one top-level attribute map end-to-end:
BuildMultiContextandBuildSingleContextnow takeMap<String, Value>instead of re-readingevaluationContext.asMap(). OutputLDContextbehavior is unchanged; only read-only views are used where copies were unnecessary.Reviewed by Cursor Bugbot for commit 8f8aeac. Bugbot is set up for automated code reviews on this repo. Configure here.