Skip to content

Replace InitializedOnce with OnceLock #1231

Open
@wks

Description

@wks

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 #1142 (comment), 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-utilsArea: UtilitiesC-cleanupCategory: CleanupF-good-first-issueCall For Participation: Suitable issues for first-time contributorsG-safetyGoal: Safety

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions