Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(turbo-tasks): Use native async traits for TaskInput (not the asy…
…nc_trait macro) (vercel#70084) ## What? Use rustc's relatively new native support for async traits: https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html Instead of the `async_trait` macro: https://docs.rs/async-trait/latest/async_trait/ The main differences are: - `async_trait` supports dynamic dispatch. The compiler-native version does not yet. - The compiler-native version often requires using messier `-> impl Future<...> + Send + '_` return types to declare additional bounds (usually `Send`). - `async_trait` forcibly boxes your returned `Future<...>` as a `Box<dyn Future<...>>`. ## Why? - We don't need dynamic dispatch. - Most of the `TaskInput` code is macro-generated, so the uglier `impl Future` syntax doesn't matter. - This is a hot codepath, and there's overhead associated with boxing a `dyn Future`. Removing the dynamic dispatch avoids pointer indirection and gives the compiler more opportunities to inline code. ## Benchmarks No measurable change. ``` cargo bench -p turbopack-bench -p turbopack-cli -- "hmr_to_eval/Turbopack CSR" ``` ``` bench_hmr_to_eval/Turbopack CSR/1000 modules time: [15.439 ms 15.633 ms 15.978 ms] change: [-1.3769% +1.0017% +3.3534%] (p = 0.46 > 0.05) No change in performance detected. ``` ``` TURBOPACK_BENCH_STRESS=yes cargo bench -p turbo-tasks-memory 500 ``` ``` turbo_tasks_memory_stress/fibonacci/500 time: [539.45 ms 544.10 ms 548.41 ms] thrpt: [228.39 Kelem/s 230.20 Kelem/s 232.18 Kelem/s] change: time: [-1.3718% -0.1154% +1.1538%] (p = 0.87 > 0.05) thrpt: [-1.1406% +0.1155% +1.3909%] No change in performance detected. Found 1 outliers among 20 measurements (5.00%) 1 (5.00%) low mild ```
- Loading branch information