-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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): Add a 'local' option to `#[turbo_tasks::function(.…
….)]` (#75259) Allows tasks to be marked as local using `#[turbo_tasks::function(local)]`. Local tasks are cached only for the lifetime of the nearest non-Local parent caller. Local tasks do not have a unique task id, and are not shared with the backend. Instead they use the parent task's id and store data in the backend-agnostic manager. This is useful for functions that have a low cache hit rate. Those functions could be converted to non-task functions, but that would break their function signature. This provides a mechanism for skipping caching without changing the function signature. Local tasks are already used for argument resolution, this allows other arbitrary functions to be opted-in.
- Loading branch information
Showing
12 changed files
with
113 additions
and
69 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/local_tasks.rs |
2 changes: 1 addition & 1 deletion
2
turbopack/crates/turbo-tasks-macros-tests/tests/function/fail_attribute_invalid_args.stderr
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
2 changes: 1 addition & 1 deletion
2
.../turbo-tasks-macros-tests/tests/function/fail_attribute_invalid_args_inherent_impl.stderr
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
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
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
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
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
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/local_tasks.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,34 @@ | ||
#![feature(arbitrary_self_types)] | ||
#![feature(arbitrary_self_types_pointers)] | ||
#![allow(clippy::needless_return)] // tokio macro-generated code doesn't respect this | ||
|
||
use anyhow::Result; | ||
use turbo_tasks::{test_helpers::current_task_for_testing, Vc}; | ||
use turbo_tasks_testing::{register, run, Registration}; | ||
|
||
static REGISTRATION: Registration = register!(); | ||
|
||
#[tokio::test] | ||
async fn test_local_task_id() -> Result<()> { | ||
run(®ISTRATION, || async { | ||
let local_vc = get_local_task_id(); | ||
assert!(local_vc.is_local()); | ||
assert_eq!(*local_vc.await.unwrap(), *current_task_for_testing()); | ||
|
||
let non_local_vc = get_non_local_task_id(); | ||
assert!(!non_local_vc.is_local()); | ||
assert_ne!(*non_local_vc.await.unwrap(), *current_task_for_testing()); | ||
Ok(()) | ||
}) | ||
.await | ||
} | ||
|
||
#[turbo_tasks::function(local)] | ||
fn get_local_task_id() -> Vc<u32> { | ||
Vc::cell(*current_task_for_testing()) | ||
} | ||
|
||
#[turbo_tasks::function] | ||
fn get_non_local_task_id() -> Vc<u32> { | ||
Vc::cell(*current_task_for_testing()) | ||
} |
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
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
Oops, something went wrong.