cloudflare / cloudflare/pingora

Replace once_cell dependency with std LazyLock and OnceLock

Open
#721 1 comment 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
Rust
Stars
27.4k
Forks
1.7k
Avg merge
6h 22m
Merged PRs (30d)
3

Description

## What is the problem your feature solves, or the need it fulfills?

`once_cell` provides lazy initialization primitives (`Lazy`, `OnceCell`). It's now in the standard library as `LazyLock` and `OnceLock`.
Continuing to use `once_cell` adds an unnecessary external dependency when the same functionality is now available natively in Rust's standard library.

## Describe the solution you'd like

replace all it's usages with the standard library equivalents as it will be a 1 to 1 replacement:
- `once_cell::sync::Lazy` -> `std::sync::LazyLock`
- `once_cell::sync::OnceCell` -> `std::sync::OnceLock`

except for `try_insert()`, found in pingora-runtime/src/lib.rs, as it is not stable yet [issue](https://github.com/rust-lang/rust/issues/116693), it's alternative would be doing `set()` then `get().unwrap()` till it gets stabilized.

## Describe alternatives you've considered

Keep using `once_cell`

Contributor guide

Open the contributing guide

Research direction

Search the repository for all once_cell usages and inspect pingora-runtime/src/lib.rs, especially the try_insert alternative described in the issue. Replace the listed primitives and remove the dependency; done means no remaining once_cell usage or dependency and the existing test suite passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.