Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/dev/openfeature/sdk/OpenFeatureClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class OpenFeatureClient implements Client {
private final AtomicReference<EvaluationContext> evaluationContext = new AtomicReference<>();

private final HookSupport hookSupport;
private final ClientMetadata clientMetadata;

/**
* Deprecated public constructor. Use OpenFeature.API.getClient() instead.
Expand All @@ -70,6 +71,7 @@ public OpenFeatureClient(OpenFeatureAPI openFeatureAPI, String domain, String ve
this.version = version;
this.hookSupport = new HookSupport();
this.clientHooks = new ConcurrentLinkedQueue<>();
this.clientMetadata = this::getDomain;
}

/**
Expand Down Expand Up @@ -467,7 +469,7 @@ public FlagEvaluationDetails<Value> getObjectDetails(

@Override
public ClientMetadata getMetadata() {
return this::getDomain;
return clientMetadata;
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.

medium

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:

  1. Update the class signature to:
    public class OpenFeatureClient implements Client, ClientMetadata {
  2. Remove the clientMetadata field and its initialization in the constructor.
  3. Update getMetadata() to return this as suggested below.

This completely avoids any extra field overhead and lambda allocation (reducing it to zero allocation).

Suggested change
return clientMetadata;
return this;

}

/**
Expand Down