Unverified Commit 00fb7ca8 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Experiment: defer turbo-tasks band pushes in a local slot

Ports the opt-in, not-for-merge local slot onto the lock-free PriorityRunner (#99773). Queued payloads stay in the claimable map (replacement, discard and claims unchanged); only the band push is deferred into a per-thread buffer, flushed at the end of the outermost worker poll and before blocking waits, followed by the saturated path's liveness handshake. Modes off (default), always and adaptive. Includes reworked lock-stats instrumentation, slot tests, and EXPERIMENT_LOCAL_SLOT.md with the benchmark recipe and results.
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
Co-authored-by: 's avatarNiklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent 2af3c42a
......@@ -2892,6 +2892,8 @@ async fn whole_app_module_graph_operation(
) -> Result<Vc<BaseAndFullModuleGraph>> {
let start = Instant::now();
let wall_start = SystemTime::now();
// EXPERIMENT (not for merge): mark the phase in the lock-stats file
turbo_tasks::experiment_lock_stats::mark("whole_app_module_graph_start");
let span = tracing::info_span!("whole app module graph", modules = Empty, edges = Empty);
let span_clone = span.clone();
let result = async move {
......@@ -2980,6 +2982,7 @@ async fn whole_app_module_graph_operation(
}
.instrument(span_clone)
.await;
turbo_tasks::experiment_lock_stats::mark("whole_app_module_graph_end");
turbo_tasks().send_compilation_event(Arc::new(TraceEvent::new_with_duration(
"turbopack-module-graph",
wall_start,
......
......@@ -373,6 +373,8 @@ impl<'e> ExecuteContext<'e> {
drop(task);
{
let _span = info_span!("blocking on another thread reading").entered();
// EXPERIMENT (local slot): publish deferred band pushes before blocking.
turbo_tasks::experiment_lock_stats::flush_local_slot();
listener.wait();
}
task = self.backend.storage.access_entry_mut(task_id);
......
......@@ -113,6 +113,8 @@ impl SnapshotCoordinator {
if state.snapshot_requested {
this.in_progress_operations.fetch_sub(1, Ordering::AcqRel);
this.operations_waiting.store(true, Ordering::Relaxed);
// EXPERIMENT (not for merge): publish deferred band pushes before blocking.
turbo_tasks::experiment_lock_stats::flush_local_slot();
tokio::task::block_in_place(|| {
this.snapshot_completed
.wait_while(&mut state, |s| s.snapshot_requested);
......@@ -189,6 +191,7 @@ impl SnapshotCoordinator {
// This runs in a background Tokio task; release its worker so admitted work can
// complete. The guard's drop synchronizes with this mutex when notifying. Wake up
// at `next_report` even without a notification so a long wait gets reported.
turbo_tasks::experiment_lock_stats::flush_local_slot();
tokio::task::block_in_place(|| {
self.operations_drained.wait_while_until(
&mut state,
......
This diff is collapsed.
......@@ -21,6 +21,8 @@ use tokio::time::{Timeout, timeout};
/// Its native implementation is just "register a waker, then park in a loop", so on wasm we drive
/// the listener's `Future` to completion with a parking executor, which is the same mechanism.
fn block_on_listener(listener: event_listener::EventListener) {
// EXPERIMENT (not for merge): publish deferred band pushes before blocking.
crate::experiment_lock_stats::flush_local_slot();
#[cfg(not(target_family = "wasm"))]
{
use event_listener::Listener as _;
......
This diff is collapsed.
......@@ -42,6 +42,9 @@ where
Impl: Send,
{
let mut futures = FuturesUnordered::new();
// EXPERIMENT (not for merge): traversal width gauge for
// `TURBO_TASKS_EXPERIMENT_LOCK_STATS`.
let mut gauge = crate::experiment_lock_stats::TraversalGauge::default();
// Populate `futures` with all the roots, `root_nodes` isn't required to be `Send`, so this
// has to happen outside of the future. We could require `root_nodes` to be `Send` in the
......@@ -51,6 +54,7 @@ where
VisitControlFlow::Continue => {
if let Some(handle) = self.try_enter(&node) {
let span = visit.span(&node, None);
gauge.push();
futures.push(With::new(visit.edges(&node), span, handle));
}
self.insert(None, node);
......@@ -69,6 +73,7 @@ where
loop {
match futures.next().await {
Some((parent_node, span, Ok(edges))) => {
gauge.complete();
let _guard = span.enter();
for (node, edge) in edges {
match visit.visit(&node, Some(&edge)) {
......@@ -76,6 +81,7 @@ where
if let Some(handle) = self.try_enter(&node) {
let span = visit.span(&node, Some(&edge));
let edges_future = visit.edges(&node);
gauge.push();
futures.push(With::new(edges_future, span, handle));
}
self.insert(Some((&parent_node, edge)), node);
......@@ -90,6 +96,7 @@ where
}
}
Some((_, _, Err(err))) => {
gauge.complete();
result = Err(err);
}
None => {
......
......@@ -24,6 +24,8 @@ mod dyn_task_inputs;
mod effect;
mod error;
pub mod event;
// EXPERIMENT (not for merge)
pub mod experiment_lock_stats;
pub mod graph;
mod id;
mod id_factory;
......
......@@ -62,6 +62,9 @@ impl ScopeInner {
let _span = info_span!("blocking").entered();
// EXPERIMENT (not for merge): publish deferred band pushes before blocking.
crate::experiment_lock_stats::flush_local_slot();
// Park up to 1ms without block_in_place to avoid the overhead.
const TIMEOUT: Duration = Duration::from_millis(1);
let beginning_park = Instant::now();
......
......@@ -86,6 +86,9 @@ where
Init: Fn() -> R + Send + Sync + 'env,
Merge: Fn(R, R) -> R + Send + Sync + 'env,
{
// EXPERIMENT (local slot): the caller blocks (draining, then waiting for workers), so publish
// deferred band pushes first.
crate::experiment_lock_stats::flush_local_slot();
let handle = Handle::current();
// One worker per runtime thread beyond the calling thread
let max_workers = handle.metrics().num_workers().saturating_sub(1);
......
......@@ -89,6 +89,8 @@ pub fn block_in_place<R>(f: impl FnOnce() -> R + Send) -> R
where
R: Send,
{
// EXPERIMENT (not for merge): publish deferred band pushes before blocking.
crate::experiment_lock_stats::flush_local_slot();
tokio::task::block_in_place(f)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment