Skip to content

perf: skip iterating over empty list#1969

Merged
toddbaert merged 1 commit into
open-feature:mainfrom
tobias-ibounig-dt:perf/pr-6-skip-empty
Jun 19, 2026
Merged

perf: skip iterating over empty list#1969
toddbaert merged 1 commit into
open-feature:mainfrom
tobias-ibounig-dt:perf/pr-6-skip-empty

Conversation

@tobias-ibounig-dt

@tobias-ibounig-dt tobias-ibounig-dt commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

This PR

  • Adds an early-exit guard in HookSupport.addFilteredHooks when the source collection is empty

Related Issues

None

Notes

addFilteredHooks is called four times per flag evaluation (provider, options, client, API hooks). In the common case three of those sources are empty, but a for-each loop always calls collection.iterator() before checking hasNext(), allocating a ConcurrentLinkedQueue$Itr or ArrayList$Itr unnecessarily. The isEmpty() check short-circuits before the iterator is ever created.

Metric benchmark.txt main This PR Delta vs main
run:+totalAllocatedBytes 139,359,040 107,492,056 103,293,456 −4,198,600 (−3.9%)
run:+totalAllocatedInstances 4,452,140 2,228,290 2,117,789 −110,501 (−4.9%)

Follow-up Tasks

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

Summary by CodeRabbit

Release Notes

  • Performance

    • Improved hook handling efficiency when processing empty sources.
  • Tests

    • Added test coverage for hook-source behavior with concurrent queue implementations.

Signed-off-by: Tobias Ibounig <tobias.ibounig@dynatrace.com>
@tobias-ibounig-dt tobias-ibounig-dt requested review from a team as code owners June 19, 2026 11:38
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3a4ce153-2c5d-4260-9e68-89a7e3445d5c

📥 Commits

Reviewing files that changed from the base of the PR and between cc837b1 and 96ee102.

📒 Files selected for processing (2)
  • src/main/java/dev/openfeature/sdk/HookSupport.java
  • src/test/java/dev/openfeature/sdk/HookSupportTest.java

📝 Walkthrough

Walkthrough

HookSupport.addFilteredHooks gains an early-exit guard that returns immediately when the source collection is empty. Two new unit tests cover ConcurrentLinkedQueue hook sources: one verifies empty queues produce no hooks, and another verifies a non-empty queue contributes its hook to the result.

Changes

Empty-source early exit in HookSupport

Layer / File(s) Summary
Early-exit guard and ConcurrentLinkedQueue tests
src/main/java/dev/openfeature/sdk/HookSupport.java, src/test/java/dev/openfeature/sdk/HookSupportTest.java
addFilteredHooks returns early when source.isEmpty(). Two new tests assert that empty ConcurrentLinkedQueue sources yield no hooks and that a non-empty one contributes its hook to hookSupportData.getHooks().

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding an early-exit guard to skip iterating over empty collections in HookSupport.addFilteredHooks.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.11%. Comparing base (cc837b1) to head (96ee102).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1969      +/-   ##
============================================
+ Coverage     92.11%   93.11%   +0.99%     
- Complexity      660      664       +4     
============================================
  Files            59       59              
  Lines          1624     1626       +2     
  Branches        182      183       +1     
============================================
+ Hits           1496     1514      +18     
+ Misses           80       66      -14     
+ Partials         48       46       -2     
Flag Coverage Δ
unittests 93.11% <100.00%> (+0.99%) ⬆️

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 b21f4a8 into open-feature:main Jun 19, 2026
12 checks passed
@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants