perf: skip unmodifiableMap wrapper when hookHints is empty#1953
perf: skip unmodifiableMap wrapper when hookHints is empty#1953tobias-ibounig-dt wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request optimizes the initialization of hookSupportData.hints in OpenFeatureClient.java by using Collections.emptyMap() when the hook hints are empty. A review comment points out that getHookHints() could return null, which would cause a NullPointerException when calling isEmpty(), and suggests adding a null check to handle this case safely.
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.
| var hookHints = flagOptions.getHookHints(); | ||
| hookSupportData.hints = hookHints.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(hookHints); |
There was a problem hiding this comment.
If flagOptions.getHookHints() returns null (which can happen if hookHints is explicitly set to null via the builder in FlagEvaluationOptions), calling hookHints.isEmpty() will throw a NullPointerException.
To ensure robust defensive programming, we should handle the null case gracefully by defaulting to Collections.emptyMap().
| var hookHints = flagOptions.getHookHints(); | |
| hookSupportData.hints = hookHints.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(hookHints); | |
| var hookHints = flagOptions.getHookHints(); | |
| hookSupportData.hints = hookHints == null || hookHints.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(hookHints); |
Signed-off-by: Tobias Ibounig <tobias.ibounig@dynatrace.com>
3e4b703 to
d583cd2
Compare
|




This PR
Collections.unmodifiableMap()wrapper whenhookHintsis empty (the common case)Related Issues
None
Notes
hookHintsis resolved once per flag evaluation. Previously it was always wrapped in an unmodifiable view, even when empty. This PR avoids that allocation by returningCollections.emptyMap()directly when there areno hints.
Allocation impact is negligible, but reduces on
totalAllocatedInstancescan be seen.main(baseline)run:+totalAllocatedBytesrun:+totalAllocatedInstancesFollow-up Tasks