turbo-tasks: drop once_cell, const-init TRAIT_METHOD, ctor WORKER_TASKS#93090
Merged
turbo-tasks: drop once_cell, const-init TRAIT_METHOD, ctor WORKER_TASKS#93090
Conversation
Merging this PR will degrade performance by 3.61%
Performance Changes
Comparing Footnotes
|
mmastrac
commented
Apr 21, 2026
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Apr 21, 2026
8211773 to
ab325cd
Compare
lukesandberg
approved these changes
Apr 21, 2026
…_TASKS - Replace `once_cell::sync::Lazy` with `std::sync::LazyLock` throughout turbo-tasks and turbo-tasks-backend (registry, scope, macro_helpers, fuzz runtime). - Replace `once_cell::unsync::Lazy` with `std::cell::LazyCell` in update_cell.rs. - Remove the unused `OnceCell` and (now unused) `phf` re-exports from `macro_helpers`; drop `once_cell` and `phf` from turbo-tasks' Cargo deps (also drop `once_cell` from turbo-tasks-backend and its fuzz crate). - Change `TraitType::methods` from `phf::Map<&str, TraitMethod>` to `&'static [TraitMethod]` (parallel to `method_names`) and make `TraitType::get` a `const fn` using `index_of_name`. The `value_trait` macro now emits a slice literal instead of a `phf_map!`, and the `function` macro emits a plain `static TRAIT_METHOD: &'static TraitMethod = TRAIT.get(stringify!(..));` initialized at const-eval time instead of a `Lazy<&'static TraitMethod>`. - Bump `ctor` to 0.10 and convert `WORKER_TASKS` in scope.rs to a `#[ctor::ctor]` static so it's initialized once at program load with no per-access locking.
- Revert the workspace `ctor` bump from 0.10 back to 0.8. The
`#[ctor::ctor] static WORKER_TASKS: usize = unsafe { ... }` form is
supported in 0.8 when the RHS is a block expression, so no change to
the scope.rs call site is required.
- `TraitType::get` is now `#[cfg(test)]`-only. Production lookup is
inlined at the macro site: the `function` macro emits
`&TRAIT.methods[macro_helpers::index_of_name(TRAIT.method_names, "name")]`,
which resolves to a const index + array deref at compile time. Re-export
`index_of_name` from `macro_helpers`.
The perf win from moving WORKER_TASKS init to load time was minimal and not worth the ctor surface in this PR. Put it back under LazyLock and drop the now-unused ctor dep from turbo-tasks.
Both stored the same data already available on `TraitType.methods[i].method_name`. Replace them with a new `index_of_method_name(&'static [TraitMethod], &str)` const fn that scans the methods slice directly. `build_trait_vtable` picks up the methods array via `<B as RegistryDef<TraitType>>::DEF.methods`, so it no longer needs `NAMES`. Drops the old `index_of_name` free fn with them. The `value_trait` macro stops emitting the parallel name list entirely — one source of truth (`methods[i].method_name`) instead of two.
ce8b8b6 to
fd76c24
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
Clean up the Lazy-locks we re-export or use internally in the turbo-tasks crates, migrating to
std::sync::LazyLock/std::cell::LazyCellwhere still needed and eliminating a couple of them where they weren't.Why
One less dep, using standard Rust features, a smaller number of Lazy items.
Details
macro_helpers::OnceCelland the now-unusedmacro_helpers::phf(sinceTraitTypeno longer stores aphf::Map). Replaceonce_cell::sync::Lazywithstd::sync::LazyLockinmacro_helpers::TRAIT_CAST_FNSand in the two macro-generated call sites.once_cell::sync::Lazy→std::sync::LazyLockinscope.rs,registry/mod.rs, andturbo-tasks-backend-fuzz'sgraph.rs.once_cell::unsync::Lazy→std::cell::LazyCellinupdate_cell.rs.TRAIT_METHOD→ plain const-init static:TraitType::methodschanges fromphf::Map<&'static str, TraitMethod>to&'static [TraitMethod](parallel tomethod_names), andTraitType::getbecomes aconst fnthat doesindex_of_name+ array indexing. Thevalue_traitmacro now emits a slice literal instead ofphf_map!, and thefunctionmacro emitsstatic TRAIT_METHOD: &'static TraitMethod = TRAIT.get(stringify!(..));— evaluated at const-eval time rather than behind aLazyLock<&TraitMethod>.once_cellandphfCargo deps fromturbo-tasks, andonce_cellfromturbo-tasks-backendand its fuzz crate.