Skip to content

Commit

Permalink
Reuse TurboTasks cross turbotrace runs (#3653)
Browse files Browse the repository at this point in the history
Allow reusing `TurboTasks` cross multiple `turbotrace` runs, can create `TurboTasks` in the next.js side and pass it back to reuse it.

Partially Close WEB-562
  • Loading branch information
Brooooooklyn committed Feb 7, 2023
1 parent 741a127 commit 9c4d81b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions crates/node-file-trace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,10 @@ fn process_input(dir: &Path, context: &str, input: &[String]) -> Result<Vec<Stri
.collect()
}

pub async fn start(args: Arc<Args>) -> Result<Vec<String>> {
pub async fn start(
args: Arc<Args>,
turbo_tasks: Option<&Arc<TurboTasks<MemoryBackend>>>,
) -> Result<Vec<String>> {
register();
let &CommonArgs {
visualize_graph,
Expand Down Expand Up @@ -406,7 +409,11 @@ pub async fn start(args: Arc<Args>) -> Result<Vec<String>> {

run(
args.clone(),
|| TurboTasks::new(MemoryBackend::new(memory_limit.unwrap_or(usize::MAX))),
|| {
turbo_tasks.cloned().unwrap_or_else(|| {
TurboTasks::new(MemoryBackend::new(memory_limit.unwrap_or(usize::MAX)))
})
},
|tt, root_task, _| async move {
if visualize_graph {
let mut stats = Stats::new();
Expand Down
2 changes: 1 addition & 1 deletion crates/node-file-trace/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn main() -> Result<()> {
console_subscriber::init();
let args = Arc::new(Args::parse());
let should_print = matches!(&*args, Args::Print { .. });
let result = start(args).await?;
let result = start(args, None).await?;
if should_print {
for file in result.iter() {
println!("{}", file);
Expand Down

2 comments on commit 9c4d81b

@vercel
Copy link

@vercel vercel bot commented on 9c4d81b Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 9c4d81b Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.