perf: cache clientMetadata lambda to avoid per-call allocation#1952
perf: cache clientMetadata lambda to avoid per-call allocation#1952tobias-ibounig-dt wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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.
| @Override | ||
| public ClientMetadata getMetadata() { | ||
| return this::getDomain; | ||
| return clientMetadata; |
There was a problem hiding this comment.
Instead of introducing a new clientMetadata field and allocating a lambda instance in the constructor, OpenFeatureClient can directly implement the ClientMetadata interface.
Since OpenFeatureClient already has a public getDomain() method (generated by Lombok's @Getter on the domain field), it already satisfies the ClientMetadata interface requirements.
To apply this optimization:
- Update the class signature to:
public class OpenFeatureClient implements Client, ClientMetadata {
- Remove the
clientMetadatafield and its initialization in the constructor. - Update
getMetadata()to returnthisas suggested below.
This completely avoids any extra field overhead and lambda allocation (reducing it to zero allocation).
| return clientMetadata; | |
| return this; |
Signed-off-by: Tobias Ibounig <tobias.ibounig@dynatrace.com>
8e1cd13 to
d66651c
Compare
|



This PR
ClientMetadatalambda in a final field to avoid re-allocating it on everygetMetadata()callRelated Issues
None
Notes
getMetadata()is called once per flag evaluation to build theSharedHookContext. Previously it returnedthis::getDomain— a new lambda instance each time. The field is initialized once in the constructor.Allocation impact is negligible, but reduces on
totalAllocatedInstancescan be seen.main(baseline)run:+totalAllocatedBytesrun:+totalAllocatedInstancesFollow-up Tasks