Skip to content

refactor(profiling): remove lazy_static, optimize Sapi/RefCellExt#3990

Merged
realFlowControl merged 6 commits into
masterfrom
florian/ponytail-cleanup
Jun 17, 2026
Merged

refactor(profiling): remove lazy_static, optimize Sapi/RefCellExt#3990
realFlowControl merged 6 commits into
masterfrom
florian/ponytail-cleanup

Conversation

@realFlowControl

@realFlowControl realFlowControl commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary

Ponytail audit cleanup for the PHP profiler.

Changes

  1. Replace lazy_static with std::sync::LazyLock (MSRV 1.87+)
  2. Add #[inline] to RefCellExt trait methods:
    I am not 100% sure about this, it is definitely not wrong, but I'd guess the compiler would inline this magically anyway?
  3. Simplify Sapi::from_name()

Powered by Kimi K2.5 and pi

You can review commit by commit (each step above is a commit)

@github-actions github-actions Bot added the profiling Relates to the Continuous Profiler label Jun 16, 2026
@realFlowControl realFlowControl force-pushed the florian/ponytail-cleanup branch 2 times, most recently from 64fce54 to c3992d9 Compare June 16, 2026 13:11
realFlowControl and others added 3 commits June 16, 2026 15:11
Rust 1.87 (MSRV) has LazyLock in std. Replace all 6 lazy_static!
deklarations with static ... LazyLock::new():
- GLOBAL_TAGS, SAPI, PROFILER_NAME_STR, PROFILER_VERSION_STR in lib.rs
- JIT_ENABLED in allocation_ge84.rs and allocation_le83.rs

Removes lazy_static dependency from Cargo.toml.

Co-authored-by: Kimi <noreply@moonshot.ai>
The RefCellExt trait is used at 20+ call sites across the codebase.
Add #[inline] attribute to:
- try_with_borrow and try_with_borrow_mut in impl block
- borrow_or_false and borrow_mut_or_false default methods

This allows LLVM to inline these small wrapper functions at call sites,
eliminating the trait dispatch overhead in optimized builds.

Co-authored-by: Kimi <noreply@moonshot.ai>
Replace OnceLock<HashMap> with a simple match expression.
The function is called exactly once per process (via LazyLock<SAPI>),
so the HashMap was unnecessary overhead.

Changes:
- Remove std::collections::HashMap and OnceLock imports
- 10-arm match instead of HashMap lookup
- Zero heap allocation, faster, clearer

Co-authored-by: Kimi <noreply@moonshot.ai>
@realFlowControl realFlowControl force-pushed the florian/ponytail-cleanup branch from c3992d9 to 8b133db Compare June 16, 2026 13:13
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Jun 16, 2026

Copy link
Copy Markdown

Pipelines  Tests

Fix all issues with BitsAI

⚠️ Warnings

🚦 5 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-php | test_extension_ci: [7.0]   View in Datadog   GitLab

DataDog/apm-reliability/dd-trace-php | test_extension_ci: [8.3]   View in Datadog   GitLab

DataDog/apm-reliability/dd-trace-php | verify windows   View in Datadog   GitLab

View all 5 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

🔄 Datadog auto-retried 1 job - 1 passed on retry View in Datadog

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 54.12% (+0.04%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 12dcedd | Docs | Datadog PR Page | Give us feedback!

@realFlowControl realFlowControl changed the title refactor(profiling): ponytail cleanup - remove lazy_static, optimize Sapi/RefCellExt refactor(profiling): remove lazy_static, optimize Sapi/RefCellExt Jun 16, 2026
@realFlowControl realFlowControl marked this pull request as ready for review June 16, 2026 13:26
@realFlowControl realFlowControl requested review from a team as code owners June 16, 2026 13:26
@pr-commenter

pr-commenter Bot commented Jun 16, 2026

Copy link
Copy Markdown

Benchmarks [ profiler ]

Benchmark execution time: 2026-06-17 14:47:20

Comparing candidate commit 12dcedd in PR branch florian/ponytail-cleanup with baseline commit 36d5401 in branch master.

Found 0 performance improvements and 3 performance regressions! Performance is the same for 26 metrics, 7 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:php-profiler-timeline-memory-control

  • 🟥 cpu_user_time [+34.681ms; +43.572ms] or [+5.778%; +7.259%]
  • 🟥 execution_time [+33.599ms; +40.747ms] or [+5.339%; +6.474%]

scenario:php-profiler-timeline-memory-with-profiler

  • 🟥 execution_time [+26.772ms; +51.943ms] or [+2.546%; +4.939%]

@realFlowControl realFlowControl marked this pull request as draft June 16, 2026 14:03
@realFlowControl realFlowControl marked this pull request as ready for review June 16, 2026 14:12
@realFlowControl realFlowControl enabled auto-merge (squash) June 16, 2026 15:49

@morrisonlevi morrisonlevi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved but note that the inline attributes on generic methods are pointless: all (or maybe nearly all?) generic methods are inlined as part of how they work.

@realFlowControl realFlowControl merged commit a8cd140 into master Jun 17, 2026
2133 of 2140 checks passed
@realFlowControl realFlowControl deleted the florian/ponytail-cleanup branch June 17, 2026 21:52
@github-actions github-actions Bot added this to the 1.22.0 milestone Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

profiling Relates to the Continuous Profiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants