Skip to content

refactor: replace lazy_static with LazyLock #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 31, 2025
Merged

Conversation

houseme
Copy link
Contributor

@houseme houseme commented Jul 31, 2025

Replace lazy_static with LazyLock.

Compile time may reduce a little.

See rust-lang-nursery/lazy-static.rs#214

Type of Change

  • New Feature
  • Bug Fix
  • Documentation
  • Performance Improvement
  • Test/CI
  • Refactor
  • Other:

Related Issues

Summary of Changes

Checklist

  • I have read and followed the CONTRIBUTING.md guidelines
  • Code is formatted with cargo fmt --all
  • Passed cargo clippy --all-targets --all-features -- -D warnings
  • Passed cargo check --all-targets
  • Added/updated necessary tests
  • Documentation updated (if needed)
  • CI/CD passed (if applicable)

Impact

  • Breaking change (compatibility)
  • Requires doc/config/deployment update
  • Other impact:

Additional Notes


Thank you for your contribution! Please ensure your PR follows the community standards (CODE_OF_CONDUCT.md) and sign the CLA if this is your first contribution.

houseme added 2 commits July 31, 2025 13:04
Replace `lazy_static` with `LazyLock`.

Compile time may reduce a little.

See rust-lang-nursery/lazy-static.rs#214
@houseme houseme requested a review from Copilot July 31, 2025 05:18
Copilot

This comment was marked as outdated.

@houseme houseme requested a review from Copilot July 31, 2025 05:27
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the codebase to replace the lazy_static macro with Rust's standard library LazyLock type for lazy initialization. This modernizes the code to use the stable stdlib feature introduced in Rust 1.80, potentially reducing compile time by removing an external dependency.

  • Migrates all static metric descriptors from lazy_static! macro to LazyLock::new()
  • Removes the lazy_static dependency from Cargo.toml
  • Updates benchmark code to use std::hint::black_box instead of criterion::black_box

Reviewed Changes

Copilot reviewed 24 out of 25 changed files in this pull request and generated 1 comment.

File Description
crates/obs/src/metrics/*.rs Convert lazy_static metric descriptors to LazyLock with improved documentation
crates/obs/Cargo.toml Remove lazy_static dependency
crates//benches/.rs Update black_box import to use std::hint instead of criterion
Cargo.toml Update criterion and rmcp versions

@houseme houseme merged commit 6c37e1c into main Jul 31, 2025
12 checks passed
@houseme houseme deleted the feature/obs-improve branch July 31, 2025 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant