refactor(profiling): remove lazy_static, optimize Sapi/RefCellExt#3990
Conversation
64fce54 to
c3992d9
Compare
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>
c3992d9 to
8b133db
Compare
|
Benchmarks [ profiler ]Benchmark execution time: 2026-06-17 14:47:20 Comparing candidate commit 12dcedd in PR branch Found 0 performance improvements and 3 performance regressions! Performance is the same for 26 metrics, 7 unstable metrics.
|
morrisonlevi
left a comment
There was a problem hiding this comment.
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.
Summary
Ponytail audit cleanup for the PHP profiler.
Changes
lazy_staticwithstd::sync::LazyLock(MSRV 1.87+)#[inline]toRefCellExttrait methods:I am not 100% sure about this, it is definitely not wrong, but I'd guess the compiler would inline this magically anyway?
Sapi::from_name()Powered by Kimi K2.5 and pi
You can review commit by commit (each step above is a commit)