Skip to content

chore: replace lazy_static with std LazyLock#5028

Closed
onx2 wants to merge 2 commits into
clockworklabs:masterfrom
onx2:chore/use-rust-lazylock
Closed

chore: replace lazy_static with std LazyLock#5028
onx2 wants to merge 2 commits into
clockworklabs:masterfrom
onx2:chore/use-rust-lazylock

Conversation

@onx2
Copy link
Copy Markdown
Contributor

@onx2 onx2 commented May 15, 2026

Description of Changes

Replaces direct lazy_static usage with standard library primitives.

Most usages were replaced with std::sync::LazyLock. One simple static list of required JWT claims was replaced with a plain const array, and an unused lazy regex in the benchmark summarizer was removed.

This also removes direct lazy_static dependencies from the workspace crates that no longer use it.

Various other deps still use it but the general ecosystem vibe is to use std instead:

This is primarily dependency hygiene rather than a performance optimization. Since this codebase targets a modern Rust version, direct lazy_static usage can be replaced with standard library primitives, reducing maintenance burden and one direct dependency.

API and ABI breaking changes

None

Expected complexity level and risk

1 - trivial, matching behavior in std

Testing

Ran:

cargo fmt --all --manifest-path SpacetimeDB/Cargo.toml

cargo check --manifest-path SpacetimeDB/Cargo.toml -p spacetimedb-bench --benches

cargo check --manifest-path SpacetimeDB/Cargo.toml -p spacetimedb-standalone

Also verified there are no remaining direct lazy_static usages in Rust source files.

Comment on lines +140 to +141
// Eventually we will want to add more required claims.
const REQUIRED_CLAIMS: [&str; 2] = ["sub", "iss"];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This seemed like it should have been const, can change to static though if I'm missing something.

Comment on lines -105 to -108
lazy_static::lazy_static! {
static ref EMOJI: Regex = Regex::new(r"(on_disk|mem)").unwrap();
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unused 🤔

@bfops
Copy link
Copy Markdown
Collaborator

bfops commented May 20, 2026

Hi @onx2, we don't really have a preference for LazyLock over lazy_static, so I'm going to close this PR.

@bfops bfops closed this May 20, 2026
@bfops bfops mentioned this pull request May 20, 2026
3 tasks
@onx2 onx2 deleted the chore/use-rust-lazylock branch May 20, 2026 18:44
@onx2
Copy link
Copy Markdown
Contributor Author

onx2 commented May 20, 2026

Hi @onx2, we don't really have a preference for LazyLock over lazy_static, so I'm going to close this PR.

Fair enough! I get wanting to avoid the code churn. I just wanted to offer the migration since std::sync::LazyLock became the official standard-library replacement back in Rust 1.80 to phase out lazy_static. Thanks for taking a look anyway!

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.

2 participants