Skip to content

perf: return ImmutableContext.EMPTY from NoOpTransactionContextPropag…#1975

Merged
toddbaert merged 1 commit into
open-feature:mainfrom
tobias-ibounig-dt:perf/pr-12-empty-from-noop-transaction-prop
Jun 19, 2026
Merged

perf: return ImmutableContext.EMPTY from NoOpTransactionContextPropag…#1975
toddbaert merged 1 commit into
open-feature:mainfrom
tobias-ibounig-dt:perf/pr-12-empty-from-noop-transaction-prop

Conversation

@tobias-ibounig-dt

@tobias-ibounig-dt tobias-ibounig-dt commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

This PR

NoOpTransactionContextPropagator.getTransactionContext() is called on every flag evaluation to retrieve the transaction context. The default implementation returned new ImmutableContext() on every call, allocating a new ImmutableContext, ImmutableStructure, and a HashMap each time — even though the result is always semantically identical.

Fix

Return the existing ImmutableContext.EMPTY singleton instead of allocating a new instance. Since ImmutableContext is immutable and NoOpTransactionContextPropagator always returns an empty context, the singleton is a correct and safe substitute.

Benchmark

Metric Before After Delta
run:+totalAllocatedInstances 2,252,509 2,013,891 −238,618 (−10.6%)
run:+totalAllocatedBytes 107,492,056 103,293,456 −4,198,600 (−3.9%)

Follow-up Tasks

  • Update benchmark.txt after all PRs are applied

…ator

Signed-off-by: Tobias Ibounig <tobias.ibounig@dynatrace.com>
@tobias-ibounig-dt tobias-ibounig-dt requested review from a team as code owners June 19, 2026 11:43
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

NoOpTransactionContextPropagator.getTransactionContext() is changed to return the shared ImmutableContext.EMPTY singleton instead of constructing a new ImmutableContext on each call. A new unit test verifies the returned instance is the same singleton via identity equality.

Changes

NoOpTransactionContextPropagator singleton return

Layer / File(s) Summary
Return ImmutableContext.EMPTY singleton and verify identity
src/main/java/dev/openfeature/sdk/NoOpTransactionContextPropagator.java, src/test/java/dev/openfeature/sdk/NoOpTransactionContextPropagatorTest.java
getTransactionContext() returns ImmutableContext.EMPTY instead of new ImmutableContext(); new test getTransactionContextReturnsEmptySingleton asserts the result is the same singleton instance using assertThat(...).isSameInstanceAs(ImmutableContext.EMPTY).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main optimization: returning ImmutableContext.EMPTY singleton from NoOpTransactionContextPropagator instead of allocating new instances.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.10%. Comparing base (cc837b1) to head (ee09adf).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1975      +/-   ##
============================================
+ Coverage     92.11%   93.10%   +0.98%     
- Complexity      660      663       +3     
============================================
  Files            59       59              
  Lines          1624     1624              
  Branches        182      182              
============================================
+ Hits           1496     1512      +16     
+ Misses           80       66      -14     
+ Partials         48       46       -2     
Flag Coverage Δ
unittests 93.10% <100.00%> (+0.98%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@toddbaert toddbaert merged commit 78afa98 into open-feature:main Jun 19, 2026
13 checks passed
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants