perf

Attribute Macro perf 

Source
#[perf]
Expand description

Marks a test as perf-sensitive, to be triaged when checking the performance of a build. This also automatically applies #[test].

§Usage

Applying this attribute to a test marks it as average importance by default. There are 5 levels of importance (Critical, Important, Average, Iffy, Fluff); see the documentation on Importance for details. Add the importance as a parameter to override the default (e.g. #[perf(important)]).

Each test also has a weight factor. This is irrelevant on its own, but is considered when comparing results across different runs. By default, this is set to 50; pass weight = n as a parameter to override this. Note that this value is only relevant within its importance category.

By default, the number of iterations when profiling this test is auto-determined. If this needs to be overwritten, pass the desired iteration count as a parameter (#[perf(iterations = n)]). Note that the actual profiler may still run the test an arbitrary number times; this flag just sets the number of executions before the process is restarted and global state is reset.

This attribute should probably not be applied to tests that do any significant disk IO, as locks on files may not be released in time when repeating a test many times. This might lead to spurious failures.

§Examples

use zed_util_macros::perf;

#[perf]
fn generic_test() {
    // Test goes here.
}

#[perf(fluff, weight = 30)]
fn cold_path_test() {
    // Test goes here.
}

This also works with #[gpui::test]s, though in most cases it shouldn’t be used with automatic iterations.

use zed_util_macros::perf;

#[perf(iterations = 1, critical)]
#[gpui::test]
fn oneshot_test(_cx: &mut gpui::TestAppContext) {
    // Test goes here.
}