Repository navigation
perf: avoid copying the evaluation context - #78
Merged
Merged
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.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Member
|
Hello @TSFenwick, Thank you for the contribution! I'm going to make a couple minor comment changes and also look to see if the optimization can be extended to the ValueConverter. |
keelerm84
approved these changes
Dec 2, 2026
kinyoklion
pushed a commit
that referenced
this pull request
Dec 3, 2026
🤖 I have created a release *beep* *boop* --- ## [2.0.2](2.0.1...2.0.2) (2026-12-02) ### Performance Improvements * avoid copying the evaluation context ([#78](#78)) ([d51aad4](d51aad4)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Bumps the library to **2.0.2** via Release Please: `gradle.properties`, `.release-please-manifest.json`, and **CHANGELOG** now record the **2.0.2** release (2026-12-02). > > The changelog entry documents a **performance improvement** from [#78](https://github.com/launchdarkly/openfeature-java-server/issues/78)—avoiding unnecessary copying of the OpenFeature **evaluation context** during flag evaluation. No application code changes appear in this PR; it only packages and documents that already-merged fix for release. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 24079d9. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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
This PR removes redundant map copies when converting OpenFeature evaluation contexts to LaunchDarkly
LDContexton the flag-evaluation path.EvaluationContextConverternow callsasUnmodifiableMap()once on the top-level context and reuses that map for single- and multi-kind builds, instead of repeatedasMap()calls that allocate copies.BuildMultiContexttakes the attribute map directly, and nested multi-kind structures also useasUnmodifiableMap().ValueConverterusesasUnmodifiableMap()when iterating structure attributes during conversion, for the same reason.Behavior is unchanged (read-only access). A new test asserts structure conversion goes through
asUnmodifiableMap().Reviewed by Cursor Bugbot for commit d4a806e. Bugbot is set up for automated code reviews on this repo. Configure here.