-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../turbo-tasks-testing/tests/performance.rs |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../turbo-tasks-testing/tests/performance.rs |
100 changes: 100 additions & 0 deletions
100
turbopack/crates/turbo-tasks-testing/tests/performance.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#![feature(arbitrary_self_types)] | ||
|
||
use std::time::Duration; | ||
|
||
use turbo_tasks::Vc; | ||
use turbo_tasks_testing::{register, run, Registration}; | ||
|
||
static REGISTRATION: Registration = register!(); | ||
|
||
const COUNT1: u32 = 100; | ||
const COUNT2: u32 = 2000; | ||
|
||
#[tokio::test] | ||
async fn many_calls_to_many_children() { | ||
run(®ISTRATION, || async { | ||
// The first call will actually execute many_children and its children. | ||
let start = std::time::Instant::now(); | ||
calls_many_children(0).strongly_consistent().await?; | ||
println!("Initial call took {:?}", start.elapsed()); | ||
|
||
// The second call will connect to the cached many_children, but it would be ok if that's | ||
// not yet optimized. | ||
let start = std::time::Instant::now(); | ||
calls_many_children(1).strongly_consistent().await?; | ||
println!("Second call took {:?}", start.elapsed()); | ||
|
||
// Susbsequent calls should be very fast. | ||
let start = std::time::Instant::now(); | ||
for i in 2..COUNT1 { | ||
calls_many_children(i).strongly_consistent().await?; | ||
} | ||
let subsequent = start.elapsed(); | ||
println!( | ||
"First {} subsequent calls took {:?}", | ||
COUNT1 - 2, | ||
subsequent | ||
); | ||
|
||
let start = std::time::Instant::now(); | ||
for i in COUNT1..COUNT1 * 2 - 2 { | ||
calls_many_children(i).strongly_consistent().await?; | ||
} | ||
let subsequent2 = start.elapsed(); | ||
println!( | ||
"Another {} subsequent calls took {:?}", | ||
COUNT1 - 2, | ||
subsequent2 | ||
); | ||
|
||
let start = std::time::Instant::now(); | ||
calls_many_children(COUNT1 - 1) | ||
.strongly_consistent() | ||
.await?; | ||
let final_call = start.elapsed(); | ||
println!("Final call took {:?}", final_call); | ||
|
||
assert!( | ||
subsequent2 * 2 < subsequent * 3, | ||
"Performance should not regress with more calls" | ||
); | ||
|
||
assert!( | ||
subsequent < Duration::from_micros(100) * (COUNT1 - 2), | ||
"Each call should be less than 100µs" | ||
); | ||
|
||
assert!( | ||
subsequent2 < Duration::from_micros(100) * (COUNT1 - 2), | ||
"Each call should be less than 100µs" | ||
); | ||
|
||
anyhow::Ok(()) | ||
}) | ||
.await | ||
.unwrap() | ||
} | ||
|
||
#[turbo_tasks::value] | ||
struct Value { | ||
value: u32, | ||
} | ||
|
||
#[turbo_tasks::function] | ||
async fn calls_many_children(_i: u32) -> Vc<()> { | ||
let _ = many_children(); | ||
Vc::cell(()) | ||
} | ||
|
||
#[turbo_tasks::function] | ||
fn many_children() -> Vc<()> { | ||
for i in 0..COUNT2 { | ||
let _ = many_children_inner(i); | ||
} | ||
Vc::cell(()) | ||
} | ||
|
||
#[turbo_tasks::function] | ||
fn many_children_inner(_i: u32) -> Vc<()> { | ||
Vc::cell(()) | ||
} |