perf: look up EventsCBGExecutor timers by an id instead of weak_ptr #3424
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 372 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.354
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3424"
general
weight: 0.35
skyegalaxy
Description
<!--
Please include a summary of the changes and the related issue.
Highlight any key points or areas of concern.
-->
Follow-up to #3315, which fixed a use-after-free of removed timers by using weak ptrs in the timer done / reset callbacks. The additional allocation and copy / lock introduced some slight overhead in performance, which this PR reduces while still keeping the thread safety fixes.
[id, this]in the done and on_reset callbacks, look up the timer by ID under the queue mutexremove_if_dropped()erases by ID instead of searchingall_timers<!--
Automatically closes linked issue when PR is merged.
Usage:
Fixes #<issue number>, orFixes (paste link of issue).-->
Fixes # (issue)
Is this user-facing behavior change?
<!--
If no, just leave this section empty.
If yes, please explain how user-experience changes with this pull request.
-->
No, aside from a minor performance improvement over #3315
Did you use Generative AI?
<!--
If this pull request was generated using Generative AI, please specify the tool and model used (e.g., GitHub Copilot, GPT-4.1).
If only specific parts were generated by Generative AI, please list those parts (e.g., function A, class B, etc.).
-->
Yes, Claude Fable 5.2
Additional Information
<!--
If applicable, provide any additional context or details about the changes.
-->
Benchmarks.
irobot_benchmarkfrom ros2-performance (ros2/ros2-performance#10,96b2147) with theEventsCBGExecutor, rmw_fastrtps_cpp, intra-process on. rclcpp rolling9e66d4d2before and after this PR, medians of 10 runs of 10 s, interleaved. p is a two-sided permutation test on the difference of medians, not adjusted for the number of comparisons.System: AMD Ryzen 9 9950X3D, pinned to 4 cores
| timers | threads | rolling | this PR | change | p |
| --: | --: | --: | --: | --- | --: |
| 20 | 1 | 0.1193 | 0.1153 | -3.3% | <0.001 |
| 20 | 4 | 0.1981 | 0.1938 | -2.2% | <0.001 |
| 50 | 1 | 0.3674 | 0.3440 | -6.4% | <0.001 |
| 50 | 4 | 0.8417 | 0.8137 | -3.3% | <0.001 |
| 200 | 1 | 0.3421 | 0.3228 | -5.6% | <0.001 |
| 200 | 4 | 0.7201 | 0.6964 | -3.3% | 0.001 |
TimerQueuethreads use about 10% less in the 50 and 200 timer cellsHeap allocations per delivered message, counted with an
LD_PRELOADmalloc counter (1 thread / 4 threads):| topology | rolling | this PR |
| --- | --: | --: |
| 50 timers | 20.62 / 20.57 | 14.61 / 14.59 |
| mont_blanc (ros2_performance) | 16.66 / 16.13 | 13.07 / 12.53 |
This should be backported over #3315 for performance reasons