perf: return ImmutableContext.EMPTY from NoOpTransactionContextPropag…#1975
Conversation
…ator Signed-off-by: Tobias Ibounig <tobias.ibounig@dynatrace.com>
📝 WalkthroughWalkthrough
ChangesNoOpTransactionContextPropagator singleton return
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|



This PR
NoOpTransactionContextPropagator.getTransactionContext()is called on every flag evaluation to retrieve the transaction context. The default implementation returnednew ImmutableContext()on every call, allocating a newImmutableContext,ImmutableStructure, and aHashMapeach time — even though the result is always semantically identical.Fix
Return the existing
ImmutableContext.EMPTYsingleton instead of allocating a new instance. SinceImmutableContextis immutable andNoOpTransactionContextPropagatoralways returns an empty context, the singleton is a correct and safe substitute.Benchmark
run:+totalAllocatedInstancesrun:+totalAllocatedBytesFollow-up Tasks
benchmark.txtafter all PRs are applied