Unverified Commit 723c0620 authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

switch our test benchmark runs to release-with-assertions (#94538)

In ci when testing our benchmarks use our test profile
`release-with-assertions`

This avoids an expensive `lto` step and ensures that our tests run with
debug asserts.

I noticed that our workflow for 'test cargo benches' was very slow and a
lot of that time was the build presumably due to lto overheads across so
many benchmark binaries.


Compare:

* cargo benches for this pr:
https://github.com/vercel/next.js/runs/79974366863?pr=94538
   - build=4m42s
   - test=1m46s
* cargo benches before this pr:
https://github.com/vercel/next.js/actions/runs/27097792020/job/79973082715#logs
   - build=8m23s
   - test=6m56s

Of course doing this revealed a few things

* a birthday paradox panic in one of the persistence tests
* some 'top level read' errors to address in the benchmarks and in the
turbopack-cli server used for some benchmarks.

And finally, that the persistence tests are just extremely slow in test
mode due to their initialization overhead (populating >1GB dbs), so that
harness is rewritten to remove some variants and also to reduce max
sizes in test mode
parent d11f61b1
...@@ -57,21 +57,21 @@ jobs: ...@@ -57,21 +57,21 @@ jobs:
- name: Build benchmarks for tests - name: Build benchmarks for tests
timeout-minutes: 120 timeout-minutes: 120
run: | run: |
cargo test --benches --workspace --release --no-fail-fast --exclude turbopack-bench --exclude next-napi-bindings --no-run cargo test --benches --workspace --profile=release-with-assertions --no-fail-fast --exclude turbopack-bench --exclude next-napi-bindings --no-run
- name: Run cargo test on benchmarks - name: Run cargo test on benchmarks
timeout-minutes: 120 timeout-minutes: 120
run: | run: |
cargo test --benches --workspace --release --no-fail-fast --exclude turbopack-bench --exclude next-napi-bindings cargo test --benches --workspace --profile=release-with-assertions --no-fail-fast --exclude turbopack-bench --exclude next-napi-bindings
- name: Build benchmarks for tests for other bundlers - name: Build benchmarks for tests for other bundlers
if: inputs.all if: inputs.all
timeout-minutes: 120 timeout-minutes: 120
run: | run: |
cargo test --benches --release -p turbopack-bench --no-run cargo test --benches --profile=release-with-assertions -p turbopack-bench --no-run
- name: Run cargo test on benchmarks for other bundlers - name: Run cargo test on benchmarks for other bundlers
if: inputs.all if: inputs.all
timeout-minutes: 120 timeout-minutes: 120
run: | run: |
cargo test --benches --release -p turbopack-bench cargo test --benches --profile=release-with-assertions -p turbopack-bench
...@@ -10456,6 +10456,7 @@ name = "turbopack-cli-utils" ...@@ -10456,6 +10456,7 @@ name = "turbopack-cli-utils"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait",
"crossterm 0.26.1", "crossterm 0.26.1",
"owo-colors", "owo-colors",
"rustc-hash 2.1.1", "rustc-hash 2.1.1",
......
...@@ -16,6 +16,7 @@ workspace = true ...@@ -16,6 +16,7 @@ workspace = true
[dependencies] [dependencies]
anyhow = { workspace = true } anyhow = { workspace = true }
async-trait = { workspace = true }
crossterm = "0.26.0" crossterm = "0.26.0"
owo-colors = { workspace = true } owo-colors = { workspace = true }
rustc-hash = { workspace = true } rustc-hash = { workspace = true }
......
...@@ -8,15 +8,16 @@ use std::{ ...@@ -8,15 +8,16 @@ use std::{
}; };
use anyhow::Result; use anyhow::Result;
use async_trait::async_trait;
use crossterm::style::{StyledContent, Stylize}; use crossterm::style::{StyledContent, Stylize};
use owo_colors::{OwoColorize as _, Style}; use owo_colors::{OwoColorize as _, Style};
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{RawVc, TransientInstance, TransientValue, Vc}; use turbo_tasks::{RawVc, ReadRef, TransientInstance, Vc};
use turbo_tasks_fs::{FileLinesContent, source_context::get_source_context}; use turbo_tasks_fs::{FileLinesContent, source_context::get_source_context};
use turbopack_core::issue::{ use turbopack_core::issue::{
CollectibleIssuesExt, IssueFilter, IssueReporter, IssueSeverity, PlainIssue, PlainIssueSource, IssueReporter, IssueSeverity, PlainIssue, PlainIssueSource, PlainIssues, PlainTraceItem,
PlainTraceItem, StyledString, StyledString,
}; };
use crate::source_context::format_source_context_lines; use crate::source_context::format_source_context_lines;
...@@ -366,7 +367,7 @@ impl PartialEq for ConsoleUi { ...@@ -366,7 +367,7 @@ impl PartialEq for ConsoleUi {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl ConsoleUi { impl ConsoleUi {
#[turbo_tasks::function] #[turbo_tasks::function(root)]
pub fn new(options: TransientInstance<LogOptions>) -> Vc<Self> { pub fn new(options: TransientInstance<LogOptions>) -> Vc<Self> {
ConsoleUi { ConsoleUi {
options: (*options).clone(), options: (*options).clone(),
...@@ -376,15 +377,15 @@ impl ConsoleUi { ...@@ -376,15 +377,15 @@ impl ConsoleUi {
} }
} }
#[async_trait]
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl IssueReporter for ConsoleUi { impl IssueReporter for ConsoleUi {
#[turbo_tasks::function]
async fn report_issues( async fn report_issues(
&self, &self,
source: TransientValue<RawVc>, issues: ReadRef<PlainIssues>,
source: RawVc,
min_failing_severity: IssueSeverity, min_failing_severity: IssueSeverity,
) -> Result<Vc<bool>> { ) -> Result<bool> {
let issues = source.peek_issues();
let LogOptions { let LogOptions {
ref current_dir, ref current_dir,
ref project_dir, ref project_dir,
...@@ -395,7 +396,7 @@ impl IssueReporter for ConsoleUi { ...@@ -395,7 +396,7 @@ impl IssueReporter for ConsoleUi {
} = self.options; } = self.options;
let mut grouped_issues: GroupedIssues = FxHashMap::default(); let mut grouped_issues: GroupedIssues = FxHashMap::default();
let plain_issues = issues.get_plain_issues(&IssueFilter::everything()).await?; let plain_issues = &issues.0;
let issues = plain_issues let issues = plain_issues
.iter() .iter()
.map(|plain_issue| { .map(|plain_issue| {
...@@ -405,11 +406,7 @@ impl IssueReporter for ConsoleUi { ...@@ -405,11 +406,7 @@ impl IssueReporter for ConsoleUi {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let issue_ids = issues.iter().map(|(_, id)| *id).collect::<FxHashSet<_>>(); let issue_ids = issues.iter().map(|(_, id)| *id).collect::<FxHashSet<_>>();
let mut new_ids = self let mut new_ids = self.seen.lock().unwrap().new_ids(source, issue_ids);
.seen
.lock()
.unwrap()
.new_ids(source.into_value(), issue_ids);
let mut has_fatal = false; let mut has_fatal = false;
for (plain_issue, id) in issues { for (plain_issue, id) in issues {
...@@ -539,7 +536,7 @@ impl IssueReporter for ConsoleUi { ...@@ -539,7 +536,7 @@ impl IssueReporter for ConsoleUi {
} }
} }
Ok(Vc::cell(has_fatal)) Ok(has_fatal)
} }
} }
......
...@@ -16,9 +16,9 @@ use serde::{Deserialize, Serialize}; ...@@ -16,9 +16,9 @@ use serde::{Deserialize, Serialize};
use turbo_esregex::EsRegex; use turbo_esregex::EsRegex;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ use turbo_tasks::{
CollectiblesSource, NonLocalValue, OperationVc, RawVc, ReadRef, ResolvedVc, TransientValue, CollectiblesSource, NonLocalValue, OperationVc, RawVc, ReadRef, ResolvedVc, TryFlatJoinIterExt,
TryFlatJoinIterExt, TryJoinIterExt, Upcast, ValueDefault, ValueToString, ValueToStringRef, Vc, TryJoinIterExt, Upcast, ValueDefault, ValueToString, ValueToStringRef, Vc, emit,
emit, trace::TraceRawVcs, trace::TraceRawVcs,
}; };
use turbo_tasks_fs::{ use turbo_tasks_fs::{
FileContent, FileLine, FileLinesContent, FileSystem, FileSystemPath, glob::Glob, FileContent, FileLine, FileLinesContent, FileSystem, FileSystemPath, glob::Glob,
...@@ -904,6 +904,14 @@ pub struct PlainIssue { ...@@ -904,6 +904,14 @@ pub struct PlainIssue {
pub import_traces: Vec<PlainTrace>, pub import_traces: Vec<PlainTrace>,
} }
/// A collection of [`PlainIssue`]s collected from a single source.
///
/// Returned by [`collect_issues`] so that the (plain) issues can be read strongly
/// consistently from a top-level task and handed to a non-turbo-task [`IssueReporter`].
#[turbo_tasks::value(serialization = "skip")]
#[derive(Debug)]
pub struct PlainIssues(pub Vec<ReadRef<PlainIssue>>);
#[turbo_tasks::value(serialization = "skip")] #[turbo_tasks::value(serialization = "skip")]
#[derive(Clone, Debug, PartialOrd, Ord)] #[derive(Clone, Debug, PartialOrd, Ord)]
pub struct PlainAdditionalIssueSource { pub struct PlainAdditionalIssueSource {
...@@ -1062,24 +1070,30 @@ impl PlainSource { ...@@ -1062,24 +1070,30 @@ impl PlainSource {
} }
} }
#[async_trait]
#[turbo_tasks::value_trait] #[turbo_tasks::value_trait]
pub trait IssueReporter { pub trait IssueReporter {
/// Reports issues to the user (e.g. to stdio). Returns whether fatal /// Reports already-collected issues to the user (e.g. to stdio). Returns whether fatal
/// (program-ending) issues were present. /// (program-ending) issues were present.
/// ///
/// This is intentionally *not* a `#[turbo_tasks::function]`: it performs no turbo-tasks
/// reads of its own (the issues are collected ahead of time by [`collect_issues`]), so it
/// is safe to call from a top-level task.
///
/// # Arguments: /// # Arguments:
/// ///
/// * `source` - The root [Vc] from which issues are traced. Can be used by implementers to /// * `issues` - The plain issues already collected from the source.
/// determine which issues are new. This must be derived from the OperationVc so issues can /// * `source` - The root [`RawVc`] from which the issues were traced. Can be used by
/// be collected. /// implementers as a dedup key to determine which issues are new. This must be derived from
/// * `min_failing_severity` - The minimum Vc<[IssueSeverity]> /// the `OperationVc` the issues were collected from.
/// The minimum issue severity level considered to fatally end the program. /// * `min_failing_severity` - The minimum issue severity level considered to fatally end the
#[turbo_tasks::function] /// program.
fn report_issues( async fn report_issues(
self: Vc<Self>, &self,
source: TransientValue<RawVc>, issues: ReadRef<PlainIssues>,
source: RawVc,
min_failing_severity: IssueSeverity, min_failing_severity: IssueSeverity,
) -> Vc<bool>; ) -> Result<bool>;
} }
pub trait CollectibleIssuesExt pub trait CollectibleIssuesExt
...@@ -1117,6 +1131,21 @@ where ...@@ -1117,6 +1131,21 @@ where
} }
} }
/// Collects all issues emitted by `source` as resolved [`PlainIssue`]s.
///
/// This is an `operation` function so its (plain) result can be read *strongly consistently* (via
/// [`OperationVc::read_strongly_consistent`]) from a top-level task without tripping the
/// eventually-consistent-read assertion. The per-issue `PlainIssue::from_issue` reads happen
/// *inside* this task, where eventually-consistent reads are legal.
#[turbo_tasks::function(operation, root)]
async fn collect_issues(source: OperationVc<()>) -> Result<Vc<PlainIssues>> {
let plain = source
.peek_issues()
.get_plain_issues(&IssueFilter::everything())
.await?;
Ok(PlainIssues(plain).cell())
}
/// A helper function to print out issues to the console. /// A helper function to print out issues to the console.
/// ///
/// Must be called in a turbo-task as this constructs a `cell` /// Must be called in a turbo-task as this constructs a `cell`
...@@ -1129,13 +1158,31 @@ pub async fn handle_issues<T: Send>( ...@@ -1129,13 +1158,31 @@ pub async fn handle_issues<T: Send>(
) -> Result<()> { ) -> Result<()> {
let source_vc = source_op.connect(); let source_vc = source_op.connect();
let _ = source_op.resolve().strongly_consistent().await?; let _ = source_op.resolve().strongly_consistent().await?;
let source_raw = Vc::into_raw(source_vc);
// Collect the issues in a dedicated `operation` task and read its *plain* result strongly
// consistently. This is safe at the top level (unlike an eventually-consistent read), while
// the per-issue reads happen inside `collect_issues`. The source is type-erased to
// `OperationVc<()>` so a single non-generic task can collect issues for any source.
let erased_source = OperationVc::<()>::try_from(source_raw)?;
let issues = collect_issues(erased_source)
.read_strongly_consistent()
.await?;
let has_fatal = issue_reporter.report_issues( // `report_issues` is a plain async method; reach it via a `TraitRef`. Resolve the reporter
TransientValue::new(Vc::into_raw(source_vc)), // strongly consistently first so that `into_trait_ref` is a plain cell read (rather than an
min_failing_severity, // eventually-consistent task-output read) at the top level.
); let reporter = issue_reporter
.to_resolved()
.strongly_consistent()
.await?
.into_trait_ref()
.await?;
let has_fatal = reporter
.report_issues(issues, source_raw, min_failing_severity)
.await?;
if *has_fatal.await? { if has_fatal {
let mut message = "Fatal issue(s) occurred".to_owned(); let mut message = "Fatal issue(s) occurred".to_owned();
if let Some(path) = path.as_ref() { if let Some(path) = path.as_ref() {
message += &format!(" in {path}"); message += &format!(" in {path}");
......
...@@ -30,8 +30,8 @@ use socket2::{Domain, Protocol, Socket, Type}; ...@@ -30,8 +30,8 @@ use socket2::{Domain, Protocol, Socket, Type};
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
use tracing::{Instrument, Level, Span, event, info_span}; use tracing::{Instrument, Level, Span, event, info_span};
use turbo_tasks::{ use turbo_tasks::{
Effects, NonLocalValue, OperationVc, PrettyPrintError, TurboTasksApi, Vc, Completion, Effects, NonLocalValue, OperationVc, PrettyPrintError, ResolvedVc, TurboTasksApi,
read_strongly_consistent_and_apply_effects, run_once_with_reason, take_effects, Vc, read_strongly_consistent_and_apply_effects, run_once_with_reason, take_effects,
trace::TraceRawVcs, util::FormatDuration, trace::TraceRawVcs, util::FormatDuration,
}; };
use turbopack_core::issue::{IssueReporter, IssueSeverity, handle_issues}; use turbopack_core::issue::{IssueReporter, IssueSeverity, handle_issues};
...@@ -71,6 +71,19 @@ async fn get_source_with_issues_operation( ...@@ -71,6 +71,19 @@ async fn get_source_with_issues_operation(
Ok(ContentSourceWithIssues { source_op, effects }.cell()) Ok(ContentSourceWithIssues { source_op, effects }.cell())
} }
/// Applies all collected [`ContentSourceSideEffect`]s. The individual `apply()` reads happen
/// *inside* this task (where eventually-consistent reads are legal); the caller reads the result
/// strongly consistently so the work is finished before the response is observed.
#[turbo_tasks::function(operation, root)]
async fn apply_side_effects_operation(
side_effects: Vec<ResolvedVc<Box<dyn ContentSourceSideEffect>>>,
) -> Result<Vc<Completion>> {
for side_effect in &side_effects {
side_effect.apply().await?;
}
Ok(Completion::new())
}
#[derive(TraceRawVcs, Debug, NonLocalValue)] #[derive(TraceRawVcs, Debug, NonLocalValue)]
pub struct DevServerBuilder { pub struct DevServerBuilder {
#[turbo_tasks(trace_ignore)] #[turbo_tasks(trace_ignore)]
...@@ -266,13 +279,17 @@ impl DevServerBuilder { ...@@ -266,13 +279,17 @@ impl DevServerBuilder {
); );
} }
if !side_effects.is_empty() { if !side_effects.is_empty() {
let side_effects: Vec<_> = side_effects.into_iter().collect();
let join_handle = tokio::spawn(run_once_with_reason( let join_handle = tokio::spawn(run_once_with_reason(
tt.clone(), tt.clone(),
side_effects_reason, side_effects_reason,
async move { async move {
for side_effect in side_effects { // Apply the side effects inside a dedicated `operation`
side_effect.apply().await?; // task and read its result strongly consistently, so this
} // top-level task performs no eventually-consistent read.
apply_side_effects_operation(side_effects)
.read_strongly_consistent()
.await?;
Ok(()) Ok(())
}, },
)); ));
......
...@@ -111,6 +111,22 @@ fn versioned_content_update_operation( ...@@ -111,6 +111,22 @@ fn versioned_content_update_operation(
content.update(*from) content.update(*from)
} }
/// Computes the initial [`Version`] for an update stream from a resolved source request. Runs as
/// an `operation` so [`UpdateStream::new`] can read it strongly consistently from its top-level
/// task without performing an eventually-consistent read.
#[turbo_tasks::function(operation, root)]
async fn initial_version_operation(
content: OperationVc<ResolveSourceRequestResult>,
) -> Result<Vc<Box<dyn Version>>> {
Ok(match *content.read_strongly_consistent().await? {
ResolveSourceRequestResult::Static(static_content, _) => {
static_content.await?.content.version()
}
ResolveSourceRequestResult::HttpProxy(proxy_result) => Vc::upcast(proxy_result.connect()),
_ => Vc::upcast(NotFoundVersion::new()),
})
}
#[turbo_tasks::function(operation, root)] #[turbo_tasks::function(operation, root)]
async fn get_update_stream_item_operation( async fn get_update_stream_item_operation(
resource: RcStr, resource: RcStr,
...@@ -277,17 +293,13 @@ impl UpdateStream { ...@@ -277,17 +293,13 @@ impl UpdateStream {
let content = get_content.call(); let content = get_content.call();
// We can ignore issues reported in content here since [compute_update_stream] // We can ignore issues reported in content here since [compute_update_stream]
// will handle them // will handle them. This runs in a top-level task (`UpdateServer::run`'s
let version = match *content.connect().await? { // `start_once_process`), so the initial version is computed in a dedicated `operation`
ResolveSourceRequestResult::Static(static_content, _) => { // task (where the per-content reads are legal) and read strongly consistently.
static_content.await?.content.version() let version = initial_version_operation(content)
} .read_trait_strongly_consistent()
ResolveSourceRequestResult::HttpProxy(proxy_result) => { .await?;
Vc::upcast(proxy_result.connect()) let version_state = VersionState::new(version).await?;
}
_ => Vc::upcast(NotFoundVersion::new()),
};
let version_state = VersionState::new(version.into_trait_ref().await?).await?;
let _ = compute_update_stream( let _ = compute_update_stream(
resource, resource,
......
...@@ -15,7 +15,9 @@ use swc_core::{ ...@@ -15,7 +15,9 @@ use swc_core::{
visit::VisitMutWith, visit::VisitMutWith,
}, },
}; };
use turbo_tasks::{ResolvedVc, TurboTasks}; use turbo_tasks::{
ResolvedVc, TurboTasks, unmark_top_level_task_may_leak_eventually_consistent_state,
};
use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage}; use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage};
use turbopack_core::{ use turbopack_core::{
compile_time_info::CompileTimeInfo, compile_time_info::CompileTimeInfo,
...@@ -142,6 +144,10 @@ fn bench_link(b: &mut Bencher, input: &BenchInput) { ...@@ -142,6 +144,10 @@ fn bench_link(b: &mut Bencher, input: &BenchInput) {
let var_graph = var_graph.clone(); let var_graph = var_graph.clone();
async move { async move {
tt.run_once(async move { tt.run_once(async move {
// `link` performs eventually-consistent Vc reads. That trips the top-level-task
// assertion under debug-assertions, but for a benchmark (not real code) reading
// the not-yet-settled value is fine — we only care about throughput.
unmark_top_level_task_may_leak_eventually_consistent_state();
let compile_time_info = CompileTimeInfo::builder( let compile_time_info = CompileTimeInfo::builder(
Environment::new(ExecutionEnvironment::NodeJsLambda( Environment::new(ExecutionEnvironment::NodeJsLambda(
NodeJsEnvironment { NodeJsEnvironment {
......
...@@ -3,7 +3,9 @@ use std::{path::PathBuf, time::Duration}; ...@@ -3,7 +3,9 @@ use std::{path::PathBuf, time::Duration};
use anyhow::Result; use anyhow::Result;
use criterion::{BatchSize, Bencher, BenchmarkId, Criterion, criterion_group, criterion_main}; use criterion::{BatchSize, Bencher, BenchmarkId, Criterion, criterion_group, criterion_main};
use turbo_rcstr::rcstr; use turbo_rcstr::rcstr;
use turbo_tasks::{ResolvedVc, TurboTasks, Vc}; use turbo_tasks::{
ResolvedVc, TurboTasks, Vc, unmark_top_level_task_may_leak_eventually_consistent_state,
};
use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage}; use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage};
use turbo_tasks_fs::{DiskFileSystem, FileSystem}; use turbo_tasks_fs::{DiskFileSystem, FileSystem};
use turbopack_core::{ use turbopack_core::{
...@@ -136,6 +138,9 @@ fn bench_full(b: &mut Bencher, input: &BenchInput) { ...@@ -136,6 +138,9 @@ fn bench_full(b: &mut Bencher, input: &BenchInput) {
let module = tokio::task::block_in_place(|| { let module = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current() tokio::runtime::Handle::current()
.block_on(tt.run_once(async move { .block_on(tt.run_once(async move {
// See note below: benchmarks may read eventually-consistent state at the
// top level, which is fine here but trips the debug assertion otherwise.
unmark_top_level_task_may_leak_eventually_consistent_state();
let module = setup(root_dir, file, analyze_mode).await?; let module = setup(root_dir, file, analyze_mode).await?;
Ok(module) Ok(module)
})) }))
...@@ -145,6 +150,10 @@ fn bench_full(b: &mut Bencher, input: &BenchInput) { ...@@ -145,6 +150,10 @@ fn bench_full(b: &mut Bencher, input: &BenchInput) {
}, },
|(tt, module)| async move { |(tt, module)| async move {
tt.run_once(async move { tt.run_once(async move {
// `analyze_ecmascript_module` performs eventually-consistent Vc reads. Reading
// not-yet-settled state at the top level is fine for a throughput benchmark, but
// trips the top-level-task assertion under debug-assertions otherwise.
unmark_top_level_task_may_leak_eventually_consistent_state();
analyze_ecmascript_module(*module, None).await?; analyze_ecmascript_module(*module, None).await?;
Ok(()) Ok(())
}) })
......
...@@ -4,7 +4,9 @@ use criterion::{Bencher, BenchmarkId, Criterion}; ...@@ -4,7 +4,9 @@ use criterion::{Bencher, BenchmarkId, Criterion};
use regex::Regex; use regex::Regex;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ use turbo_tasks::{
Effects, OperationVc, TurboTasks, Vc, read_strongly_consistent_and_apply_effects, take_effects, Effects, OperationVc, TurboTasks, Vc, mark_top_level_task,
read_strongly_consistent_and_apply_effects, take_effects,
unmark_top_level_task_may_leak_eventually_consistent_state,
}; };
use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage}; use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage};
use turbo_tasks_fs::{DiskFileSystem, FileSystem, NullFileSystem}; use turbo_tasks_fs::{DiskFileSystem, FileSystem, NullFileSystem};
...@@ -85,6 +87,11 @@ fn bench_emit(b: &mut Bencher, bench_input: &BenchInput) { ...@@ -85,6 +87,11 @@ fn bench_emit(b: &mut Bencher, bench_input: &BenchInput) {
let input: RcStr = bench_input.input.clone().into(); let input: RcStr = bench_input.input.clone().into();
async move { async move {
tt.run_once(async move { tt.run_once(async move {
// This benchmark performs eventually-consistent Vc reads at the top level, which
// is fine for a throughput benchmark but trips the top-level-task assertion under
// debug-assertions otherwise. Unmark the top-level task for the reads, then re-mark
// it before `Effects::apply`, which *requires* a top-level task.
unmark_top_level_task_may_leak_eventually_consistent_state();
let input_fs = DiskFileSystem::new(rcstr!("tests"), Vc::cell(tests_root.clone())); let input_fs = DiskFileSystem::new(rcstr!("tests"), Vc::cell(tests_root.clone()));
let input = input_fs.root().await?.join(&input)?; let input = input_fs.root().await?.join(&input)?;
...@@ -131,13 +138,17 @@ fn bench_emit(b: &mut Bencher, bench_input: &BenchInput) { ...@@ -131,13 +138,17 @@ fn bench_emit(b: &mut Bencher, bench_input: &BenchInput) {
.to_resolved() .to_resolved()
.await?; .await?;
// `read_strongly_consistent_and_apply_effects` applies effects, which *requires* a
// top-level task. Restore the mark we cleared above for the eventually-consistent
// reads.
mark_top_level_task();
read_strongly_consistent_and_apply_effects( read_strongly_consistent_and_apply_effects(
extract_effects_operation(emit_assets_into_dir_operation(assets, output_dir)), extract_effects_operation(emit_assets_into_dir_operation(assets, output_dir)),
|e| e, |e| e,
) )
.await?; .await?;
Ok(()) anyhow::Ok(())
}) })
.await .await
.unwrap(); .unwrap();
......
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