← Back to Pull requests

perf: look up EventsCBGExecutor timers by an id instead of weak_ptr #3424

Closed
unknown closed this pull request without merging on Nov 25, 2026 18:11 UTC
View on GitHub
unknown unknown commented on Nov 19, 2026 20:18 UTC
Author

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.

  • Give each timer a unique ID and store in an unordered map

  • capture [id, this] in the done and on_reset callbacks, look up the timer by ID under the queue mutex

  • remove_if_dropped() erases by ID instead of searching all_timers
  • <!--
    Automatically closes linked issue when PR is merged.
    Usage: Fixes #<issue number>, or Fixes (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_benchmark from ros2-performance (ros2/ros2-performance#10, 96b2147) with the EventsCBGExecutor, rmw_fastrtps_cpp, intra-process on. rclcpp rolling 9e66d4d2 before 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 |

  • The executor worker threads use between 2.0% and 4.8% less CPU

  • The main and TimerQueue threads use about 10% less in the 50 and 200 timer cells

  • Mean latency is lower in two of the 4-thread cells (-1.7% and -3.3%, p < 0.001) and within 1.2% and not significant in the other four.

  • No lost or late messages in any run, identical delivered counts, and no change in peak RSS (within 0.3%, not significant).
  • Heap allocations per delivered message, counted with an LD_PRELOAD malloc 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

    Diff: 372 lines (+279 / -93) across 4 files Reviewer: skyegalaxy Review duration: 8513m
    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
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.8% (MEDIUM) · Higher = larger blast radius
    42.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.9% · Safe to merge
    16.9%
    Repository