Replace InitializedOnce with OnceLock #1231
Labels
A-utils
Area: Utilities
C-cleanup
Category: Cleanup
F-good-first-issue
Call For Participation: Suitable issues for first-time contributors
G-safety
Goal: Safety
We introduced
std::util::rust_util::InitializeOnce
in 21 January 2022 as a faster replacement oflazy_static
. Rust 1.70.0 (1 June 2023) introducedstd::cell::OnceCell
andstd::sync::OnceLock
into the standard library.OnceLock
provides the same functionality asInitializeOnce
. Since we already bumped MSRV to 1.71.1 (as inpackage.rust-version
inCargo.toml
), we can switch to theOnceLock
in the standard library.@qinsoon did a microbenchmark in #1142 (comment), showing that the performance difference between
InitializeOnce
,std::sync::OnceLock
and the third-partyonce_cell
crate is negligible. To be safe, we should do a similar microbenchmark with a use pattern ofSFTMap
(which is currently the sole user ofInitializeOnce
) and add it to themmtk-core/benches/regular_bench
directory.Note that
std::sync::OnceLock
only providesget()
andget_mut()
, both of which perform a check of whether it is initialized. We should also see if the checking is a bottleneck by comparinginitializeOnce::deref()
,std::sync::OnceLock.get
andonce_cell::sync::OnceCell::get_unchecked
.The text was updated successfully, but these errors were encountered: