perf: replace copy+reverse with index-based traversal in executeBefor…#1954
perf: replace copy+reverse with index-based traversal in executeBefor…#1954tobias-ibounig-dt wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request optimizes the executeBeforeHooks method in HookSupport.java by replacing the list copying and reversal with a reverse index-based for loop. Feedback recommends adding defensive null checks for data and data.getHooks() to prevent potential NullPointerExceptions.
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.
| List<Pair<Hook, HookContext>> hooks = data.getHooks(); | ||
| for (int i = hooks.size() - 1; i >= 0; i--) { |
There was a problem hiding this comment.
To prevent potential NullPointerExceptions, it is recommended to add a defensive null check for data and data.getHooks(). Since HookSupportData is initialized with a default constructor where hooks is not set, data.getHooks() can return null if no hooks are registered or if setHooks was not called.
| List<Pair<Hook, HookContext>> hooks = data.getHooks(); | |
| for (int i = hooks.size() - 1; i >= 0; i--) { | |
| if (data == null || data.getHooks() == null) { | |
| return; | |
| } | |
| List<Pair<Hook, HookContext>> hooks = data.getHooks(); | |
| for (int i = hooks.size() - 1; i >= 0; i--) { |
…eHooks Signed-off-by: Tobias Ibounig <tobias.ibounig@dynatrace.com>
6de83c9 to
d55981c
Compare
|




This PR
executeBeforeHookswith an index-based reverse loopRelated Issues
None
Notes
Previously
executeBeforeHookscopied the hook list into a newArrayListand calledCollections.reverse()before iterating. This allocated one extra list per flag evaluation. The change iterates the existing list in reverse using an index loop, which requires no additional allocation.main(baseline)run:+totalAllocatedBytesrun:+totalAllocatedInstancesFollow-up Tasks