Skip to content

perf: cache clientMetadata lambda to avoid per-call allocation#1952

Merged
toddbaert merged 1 commit into
open-feature:mainfrom
tobias-ibounig-dt:perf/pr-1-client-metadata
Jun 8, 2026
Merged

perf: cache clientMetadata lambda to avoid per-call allocation#1952
toddbaert merged 1 commit into
open-feature:mainfrom
tobias-ibounig-dt:perf/pr-1-client-metadata

Conversation

@tobias-ibounig-dt

Copy link
Copy Markdown
Contributor

This PR

  • Caches the ClientMetadata lambda in a final field to avoid re-allocating it on every getMetadata() call

Related Issues

None

Notes

getMetadata() is called once per flag evaluation to build the SharedHookContext. Previously it returned this::getDomain — a new lambda instance each time. The field is initialized once in the constructor.

Allocation impact is negligible, but reduces on totalAllocatedInstances can be seen.

Metric main (baseline) This PR Delta
run:+totalAllocatedBytes 124,265,984 124,265,984 0
run:+totalAllocatedInstances 2,723,316 2,674,636 −48,680 (−1.8%)

Follow-up Tasks

  • More PRs with memory improvements
  • Update benchmark.txt after all are applied

@tobias-ibounig-dt tobias-ibounig-dt requested review from a team as code owners June 5, 2026 08:22

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors OpenFeatureClient to store a clientMetadata field initialized with a lambda reference in the constructor, returning it in getMetadata(). The reviewer suggests optimizing this further by having OpenFeatureClient directly implement the ClientMetadata interface, which would allow getMetadata() to return this and completely eliminate the extra field and lambda allocation.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/main/java/dev/openfeature/sdk/OpenFeatureClient.java
@tobias-ibounig-dt tobias-ibounig-dt force-pushed the perf/pr-1-client-metadata branch from 8e1cd13 to d66651c Compare June 5, 2026 08:35
@toddbaert

Copy link
Copy Markdown
Member

Same codecov-action issue as #1955 (comment) - rebasing this PR onto main should fix it. cc @chrfwow

Signed-off-by: Tobias Ibounig <tobias.ibounig@dynatrace.com>
@toddbaert toddbaert force-pushed the perf/pr-1-client-metadata branch from d66651c to 12c0939 Compare June 8, 2026 14:47
@toddbaert toddbaert enabled auto-merge (squash) June 8, 2026 14:47
@sonarqubecloud

sonarqubecloud Bot commented Jun 8, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.27%. Comparing base (b611d55) to head (12c0939).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1952      +/-   ##
============================================
+ Coverage     92.25%   93.27%   +1.01%     
- Complexity      654      657       +3     
============================================
  Files            59       59              
  Lines          1589     1590       +1     
  Branches        179      179              
============================================
+ Hits           1466     1483      +17     
+ Misses           76       62      -14     
+ Partials         47       45       -2     
Flag Coverage Δ
unittests 93.27% <100.00%> (+1.01%) ⬆️

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 85c0047 into open-feature:main Jun 8, 2026
10 checks passed
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.

3 participants