We introduced std::util::rust_util::InitializeOnce in 21 January 2022 as a faster replacement of lazy_static. Rust 1.70.0 (1 June 2023) introduced std::cell::OnceCell and std::sync::OnceLock into the standard library. OnceLock provides the same functionality as InitializeOnce. Since we already bumped MSRV to 1.71.1 (as in package.rust-version in Cargo.toml), we can switch to the OnceLock in the standard library.
@qinsoon did a microbenchmark in https://github.com/mmtk/mmtk-core/pull/1142#discussion_r1626766882, showing that the performance difference between InitializeOnce, std::sync::OnceLock and the third-party once_cell crate is negligible. To be safe, we should do a similar microbenchmark with a use pattern of SFTMap (which is currently the sole user of InitializeOnce) and add it to the mmtk-core/benches/regular_bench directory.
Note that std::sync::OnceLock only provides get() and get_mut(), both of which perform a check of whether it is initialized. We should also see if the checking is a bottleneck by comparing initializeOnce::deref(), std::sync::OnceLock.get and once_cell::sync::OnceCell::get_unchecked.
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 https://github.com/mmtk/mmtk-core/pull/1142#discussion_r1626766882, 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
.