Skip to content

turbo-tasks: drop once_cell, const-init TRAIT_METHOD, ctor WORKER_TASKS#93090

Merged
mmastrac merged 5 commits intocanaryfrom
mmastrac/turbotasks-remove-lazy
Apr 21, 2026
Merged

turbo-tasks: drop once_cell, const-init TRAIT_METHOD, ctor WORKER_TASKS#93090
mmastrac merged 5 commits intocanaryfrom
mmastrac/turbotasks-remove-lazy

Conversation

@mmastrac
Copy link
Copy Markdown
Contributor

@mmastrac mmastrac commented Apr 21, 2026

What

Clean up the Lazy-locks we re-export or use internally in the turbo-tasks crates, migrating to std::sync::LazyLock / std::cell::LazyCell where 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

  • Re-exports: drop unused macro_helpers::OnceCell and the now-unused macro_helpers::phf (since TraitType no longer stores a phf::Map). Replace once_cell::sync::Lazy with std::sync::LazyLock in macro_helpers::TRAIT_CAST_FNS and in the two macro-generated call sites.
  • once_cell::sync::Lazystd::sync::LazyLock in scope.rs, registry/mod.rs, and turbo-tasks-backend-fuzz's graph.rs.
  • once_cell::unsync::Lazystd::cell::LazyCell in update_cell.rs.
  • TRAIT_METHOD → plain const-init static: TraitType::methods changes from phf::Map<&'static str, TraitMethod> to &'static [TraitMethod] (parallel to method_names), and TraitType::get becomes a const fn that does index_of_name + array indexing. The value_trait macro now emits a slice literal instead of phf_map!, and the function macro emits static TRAIT_METHOD: &'static TraitMethod = TRAIT.get(stringify!(..)); — evaluated at const-eval time rather than behind a LazyLock<&TraitMethod>.
  • Dropped once_cell and phf Cargo deps from turbo-tasks, and once_cell from turbo-tasks-backend and its fuzz crate.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 21, 2026

Merging this PR will degrade performance by 3.61%

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 15 untouched benchmarks
⏩ 3 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation packages-bundle.js[full] 947.9 ms 983.5 ms -3.61%
Simulation app-page-turbo.runtime.prod.js[full] 641.3 ms 619.2 ms +3.57%

Comparing mmastrac/turbotasks-remove-lazy (fd76c24) with canary (c526347)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Comment thread turbopack/crates/turbo-tasks/src/value_type.rs Outdated
Copy link
Copy Markdown
Contributor Author

mmastrac commented Apr 21, 2026

Comment thread turbopack/crates/turbo-tasks/src/value_type.rs
Comment thread turbopack/crates/turbo-tasks/src/value_type.rs Outdated
@mmastrac mmastrac force-pushed the mmastrac/turbotasks-remove-lazy branch from 8211773 to ab325cd Compare April 21, 2026 18:27
@mmastrac mmastrac enabled auto-merge (squash) April 21, 2026 19:42
…_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.
@mmastrac mmastrac force-pushed the mmastrac/turbotasks-remove-lazy branch from ce8b8b6 to fd76c24 Compare April 21, 2026 20:13
@mmastrac mmastrac merged commit c916c80 into canary Apr 21, 2026
184 of 186 checks passed
@mmastrac mmastrac deleted the mmastrac/turbotasks-remove-lazy branch April 21, 2026 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants