Skip to content

feat: schedule_relative! macro#921

Open
RobertJacobsonCDC wants to merge 1 commit into
mainfrom
RobertJacobsonCDC_914_schedule_relative
Open

feat: schedule_relative! macro#921
RobertJacobsonCDC wants to merge 1 commit into
mainfrom
RobertJacobsonCDC_914_schedule_relative

Conversation

@RobertJacobsonCDC
Copy link
Copy Markdown
Collaborator

@RobertJacobsonCDC RobertJacobsonCDC commented May 25, 2026

Implemented a convenience macro:

schedule_relative!(context, my_delay, my_action, arg1, arg2, arg3);

expands to:

context.add_plan(context.get_current_time() + my_delay, move |context| {
    my_action(context, arg1, arg2, arg3)
});

The point of the macro is:

  1. The convenience of scheduling at a relative future time instead of an absolute future time.
  2. Capturing the concrete parameter values passed to the handler without having to manually write the closure syntax.

Open Questions / Issues

  • A similar macro track_periodic_value_change_counts (feat: track_periodic_value_change_counts! macro #917) mirrors the name of the method, so maybe we want to name this add_plan_relative! instead?
  • The "relative" bit is just because the macro adds the my_delay parameter to context.get_current_time() for you. Maybe we should have "relative" versions of the methods for convenience as suggested by Ergonomics: add_plan() is absolute, not relative, time #836? Likewise, should there be an absolute time version of this schedule_relative! macro, maybe called schedule! or just add_plan!?

@RobertJacobsonCDC RobertJacobsonCDC linked an issue May 25, 2026 that may be closed by this pull request
@github-actions
Copy link
Copy Markdown

Benchmark Results

Hyperfine

Command Mean [ms] Min [ms] Max [ms] Relative
large_sir::baseline 3.2 ± 0.1 3.2 3.5 1.01 ± 0.02
large_sir::baseline_households 3.2 ± 0.0 3.2 3.3 1.00
large_sir::entities 7.4 ± 0.3 7.3 9.3 2.30 ± 0.09
large_sir::households 7.1 ± 0.1 6.8 7.5 2.22 ± 0.04

Criterion

Regressions (slower)
Group Bench Param Change CI Lower CI Upper
sampling sampling_single_unindexed_concrete_plus_derived_entities 21.413% 16.627% 26.789%
indexing query_people_multiple_individually_indexed_properties_entities 4.380% 3.877% 4.749%
indexing with_query_results_single_indexed_property_entities 3.295% 2.494% 4.067%
counts single_property_indexed_entities 2.665% 2.478% 2.853%
large_dataset bench_query_population_derived_property_entities 1.958% 1.504% 2.427%
large_dataset bench_query_population_multi_indexed_entities 1.305% 1.031% 1.559%
Improvements (faster)
Group Bench Param Change CI Lower CI Upper
sample_entity sample_entity_whole_population 100000 -25.249% -25.681% -24.847%
sample_entity sample_entity_whole_population 1000 -23.104% -24.352% -21.368%
sample_entity sample_entity_single_property_unindexed 1000 -22.563% -22.880% -22.248%
sample_entity sample_entity_whole_population 10000 -22.388% -23.078% -21.622%
sample_entity sample_entity_single_property_indexed 1000 -5.988% -6.649% -5.311%
sampling sampling_single_known_length_entities -4.440% -4.853% -4.058%
sample_entity sample_entity_single_property_indexed 10000 -3.641% -4.141% -3.094%
large_dataset bench_match_entity -3.537% -3.947% -3.089%
sample_entity sample_entity_single_property_indexed 100000 -3.454% -4.299% -2.551%
sample_entity sample_entity_multi_property_indexed 1000 -3.034% -3.355% -2.655%
sample_entity sample_entity_multi_property_indexed 100000 -2.841% -3.071% -2.552%
sample_entity sample_entity_multi_property_indexed 10000 -2.815% -3.327% -2.326%
large_dataset bench_query_population_property_entities -2.392% -3.725% -1.203%
indexing with_query_results_multiple_individually_indexed_properties_enti -1.709% -1.969% -1.464%
Unchanged / inconclusive (CI crosses 0%)
Group Bench Param Change CI Lower CI Upper
indexing query_people_count_single_indexed_property_entities 2.875% 0.215% 5.569%
large_dataset bench_filter_indexed_entity -2.224% -9.675% 6.582%
large_dataset bench_query_population_multi_unindexed_entities -2.107% -3.481% -0.831%
sampling count_and_sampling_single_known_length_entities -1.656% -2.649% -0.643%
counts index_after_adding_entities 1.009% 0.787% 1.229%
indexing query_people_count_indexed_multi-property_entities 0.879% 0.634% 1.249%
large_dataset bench_filter_unindexed_entity -0.872% -4.474% 2.752%
large_dataset bench_query_population_indexed_property_entities 0.681% 0.061% 1.482%
examples example-basic-infection -0.634% -1.410% 0.313%
counts single_property_unindexed_entities -0.599% -1.113% -0.079%
indexing query_people_indexed_multi-property_entities 0.434% 0.239% 0.682%
examples example-births-deaths 0.389% 0.250% 0.521%
sampling count_and_sampling_single_unindexed_concrete_plus_derived_entiti 0.383% 0.278% 0.501%
counts concrete_plus_derived_unindexed_entities 0.348% -0.130% 1.054%
sampling sampling_multiple_l_reservoir_entities -0.346% -1.015% 0.182%
indexing with_query_results_indexed_multi-property_entities 0.326% -0.136% 0.769%
counts reindex_after_adding_more_entities 0.306% 0.082% 0.514%
sampling sampling_multiple_known_length_entities -0.292% -0.646% 0.251%
indexing query_people_single_indexed_property_entities 0.291% 0.018% 0.640%
sampling sampling_single_l_reservoir_entities -0.272% -1.088% 0.511%
algorithm_benches algorithm_sampling_single_known_length -0.265% -0.745% 0.054%
indexing query_people_count_multiple_individually_indexed_properties_enti 0.208% 0.109% 0.301%
counts multi_property_indexed_entities 0.200% -0.314% 0.591%
algorithm_benches algorithm_sampling_single_rand_reservoir -0.191% -0.554% 0.125%
algorithm_benches algorithm_sampling_single_l_reservoir -0.182% -0.506% 0.034%
sample_entity sample_entity_single_property_unindexed 100000 -0.143% -0.450% 0.101%
sampling sampling_single_unindexed_entities 0.109% 0.056% 0.167%
algorithm_benches algorithm_sampling_multiple_known_length -0.079% -0.765% 0.580%
counts multi_property_unindexed_entities -0.051% -0.695% 0.769%
algorithm_benches algorithm_sampling_multiple_l_reservoir -0.035% -0.478% 0.444%
sample_entity sample_entity_single_property_unindexed 10000 0.018% -0.371% 0.416%
sampling sampling_multiple_unindexed_entities 0.010% -0.111% 0.099%
Not Compared (no baseline yet)
Group Bench Reason
(none)

github-actions Bot added a commit that referenced this pull request May 25, 2026
Copy link
Copy Markdown
Collaborator

@k88hudson-cfa k88hudson-cfa left a comment

Choose a reason for hiding this comment

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

One suggestion but otherwise this looks good

Comment thread src/macros/schedule_relative.rs Outdated
#[macro_export]
macro_rules! schedule_relative {
($context:expr, $delay:expr, $action:expr $(, $arg:expr)* $(,)?) => {{
let time = ($context).get_current_time() + $delay;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why not just assign let ctx = $context here to avoid the doube eval?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I should also introduce a local scope for the temporaries.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I should also introduce a local scope for the temporaries.

Oh, I do! 😄

@RobertJacobsonCDC RobertJacobsonCDC force-pushed the RobertJacobsonCDC_914_schedule_relative branch from a933441 to ceec8be Compare May 27, 2026 14:05
@RobertJacobsonCDC RobertJacobsonCDC force-pushed the RobertJacobsonCDC_914_schedule_relative branch from ceec8be to 96cb7e2 Compare May 27, 2026 14:07
github-actions Bot added a commit that referenced this pull request May 27, 2026
@github-actions
Copy link
Copy Markdown

Benchmark Results

Hyperfine

Command Mean [ms] Min [ms] Max [ms] Relative
large_sir::baseline 3.2 ± 0.0 3.1 3.4 1.00 ± 0.02
large_sir::baseline_households 3.2 ± 0.0 3.2 3.4 1.00
large_sir::entities 7.2 ± 0.1 7.1 7.5 2.24 ± 0.04
large_sir::households 7.0 ± 0.1 6.8 7.6 2.17 ± 0.05

Criterion

Regressions (slower)
Group Bench Param Change CI Lower CI Upper
sample_entity sample_entity_single_property_unindexed 10000 9.242% 7.109% 11.456%
sample_entity sample_entity_single_property_indexed 10000 3.554% 2.905% 4.056%
indexing query_people_multiple_individually_indexed_properties_entities 2.767% 1.875% 3.547%
large_dataset bench_match_entity 2.758% 2.094% 3.190%
sample_entity sample_entity_single_property_indexed 100000 2.319% 1.947% 2.810%
Improvements (faster)
Group Bench Param Change CI Lower CI Upper
sample_entity sample_entity_single_property_unindexed 1000 -21.909% -22.102% -21.696%
counts multi_property_indexed_entities -6.979% -7.974% -6.080%
sampling count_and_sampling_single_known_length_entities -6.457% -7.211% -5.670%
sampling sampling_single_known_length_entities -4.436% -6.916% -1.079%
indexing query_people_count_single_indexed_property_entities -3.321% -4.594% -2.455%
indexing with_query_results_indexed_multi-property_entities -3.093% -4.673% -1.702%
indexing query_people_indexed_multi-property_entities -2.979% -4.213% -1.817%
sampling sampling_single_unindexed_entities -2.868% -2.992% -2.694%
sampling sampling_multiple_unindexed_entities -2.251% -2.384% -2.071%
sampling sampling_multiple_l_reservoir_entities -2.207% -2.301% -2.120%
Unchanged / inconclusive (CI crosses 0%)
Group Bench Param Change CI Lower CI Upper
indexing with_query_results_single_indexed_property_entities -1.466% -2.388% -0.620%
sample_entity sample_entity_single_property_indexed 1000 1.372% 0.855% 2.048%
sample_entity sample_entity_multi_property_indexed 10000 1.359% 0.990% 1.807%
sampling count_and_sampling_single_unindexed_concrete_plus_derived_entiti -1.210% -1.479% -0.959%
examples example-births-deaths 1.195% 0.774% 1.664%
sampling sampling_single_unindexed_concrete_plus_derived_entities -1.157% -1.439% -0.882%
counts single_property_indexed_entities -1.119% -1.523% -0.709%
counts multi_property_unindexed_entities 1.075% -2.793% 4.795%
large_dataset bench_query_population_multi_indexed_entities 1.020% 0.581% 1.478%
sample_entity sample_entity_multi_property_indexed 1000 1.008% 0.689% 1.334%
sampling sampling_single_l_reservoir_entities -0.946% -1.897% -0.150%
examples example-basic-infection 0.922% 0.226% 1.736%
indexing query_people_single_indexed_property_entities 0.889% 0.826% 0.955%
counts index_after_adding_entities 0.683% -0.033% 1.188%
counts single_property_unindexed_entities -0.682% -2.071% 0.388%
sample_entity sample_entity_whole_population 100000 0.621% 0.169% 1.199%
indexing with_query_results_multiple_individually_indexed_properties_enti 0.533% -0.246% 1.329%
algorithm_benches algorithm_sampling_multiple_l_reservoir -0.462% -1.247% 0.224%
sample_entity sample_entity_whole_population 10000 0.424% -0.214% 1.075%
algorithm_benches algorithm_sampling_multiple_known_length 0.405% -0.267% 1.052%
counts concrete_plus_derived_unindexed_entities -0.377% -1.563% 0.535%
indexing query_people_count_indexed_multi-property_entities -0.374% -1.071% 0.331%
counts reindex_after_adding_more_entities -0.272% -0.561% 0.042%
indexing query_people_count_multiple_individually_indexed_properties_enti 0.271% -0.042% 0.554%
large_dataset bench_filter_unindexed_entity -0.227% -3.857% 3.731%
algorithm_benches algorithm_sampling_single_known_length 0.209% -0.421% 0.956%
large_dataset bench_query_population_property_entities -0.172% -0.693% 0.267%
large_dataset bench_query_population_multi_unindexed_entities 0.142% -0.181% 0.639%
sample_entity sample_entity_whole_population 1000 0.130% -0.670% 0.938%
sample_entity sample_entity_multi_property_indexed 100000 0.127% -0.353% 0.584%
large_dataset bench_query_population_indexed_property_entities 0.100% -0.333% 0.850%
algorithm_benches algorithm_sampling_single_rand_reservoir -0.030% -0.794% 0.715%
algorithm_benches algorithm_sampling_single_l_reservoir -0.029% -0.337% 0.391%
large_dataset bench_filter_indexed_entity -0.023% -7.953% 9.004%
sampling sampling_multiple_known_length_entities 0.017% -0.693% 0.521%
sample_entity sample_entity_single_property_unindexed 100000 0.013% -0.220% 0.331%
large_dataset bench_query_population_derived_property_entities -0.005% -0.433% 0.408%
Not Compared (no baseline yet)
Group Bench Reason
(none)

@github-actions
Copy link
Copy Markdown

Benchmark Results

Hyperfine

Command Mean [ms] Min [ms] Max [ms] Relative
large_sir::baseline 3.4 ± 0.0 3.3 3.6 1.00
large_sir::baseline_households 3.4 ± 0.0 3.4 3.6 1.01 ± 0.02
large_sir::entities 7.8 ± 0.3 7.4 9.2 2.29 ± 0.10
large_sir::households 7.7 ± 0.5 7.3 9.0 2.27 ± 0.15

Criterion

Regressions (slower)
Group Bench Param Change CI Lower CI Upper
sample_entity sample_entity_single_property_unindexed 10000 57.371% 56.562% 57.943%
sample_entity sample_entity_single_property_unindexed 1000 23.311% 21.052% 25.393%
large_dataset bench_filter_indexed_entity 14.906% 4.345% 26.912%
large_dataset bench_query_population_derived_property_entities 10.928% 8.443% 13.336%
large_dataset bench_filter_unindexed_entity 5.360% 1.320% 9.673%
Improvements (faster)
Group Bench Param Change CI Lower CI Upper
sampling count_and_sampling_single_known_length_entities -17.381% -18.571% -16.101%
indexing query_people_indexed_multi-property_entities -11.181% -12.536% -9.512%
sampling sampling_single_known_length_entities -11.051% -12.345% -9.760%
counts single_property_indexed_entities -8.069% -9.842% -6.447%
large_dataset bench_query_population_indexed_property_entities -6.615% -8.981% -4.005%
sampling sampling_single_unindexed_entities -3.336% -3.457% -3.213%
sampling sampling_multiple_unindexed_entities -2.816% -3.099% -2.601%
sample_entity sample_entity_single_property_indexed 10000 -2.321% -2.939% -1.728%
counts multi_property_indexed_entities -2.320% -3.088% -1.560%
sample_entity sample_entity_single_property_indexed 100000 -2.057% -2.722% -1.485%
Unchanged / inconclusive (CI crosses 0%)
Group Bench Param Change CI Lower CI Upper
examples example-basic-infection -1.870% -3.346% -0.655%
indexing query_people_count_single_indexed_property_entities -1.534% -2.368% -0.815%
large_dataset bench_match_entity 1.515% 0.125% 2.953%
indexing with_query_results_single_indexed_property_entities -1.482% -2.160% -0.870%
counts concrete_plus_derived_unindexed_entities 1.388% 0.024% 2.925%
algorithm_benches algorithm_sampling_single_l_reservoir -1.262% -1.794% -0.767%
examples example-births-deaths -1.228% -2.081% -0.578%
algorithm_benches algorithm_sampling_multiple_known_length 1.093% 0.519% 1.660%
sampling sampling_multiple_known_length_entities 1.077% 0.583% 1.744%
sample_entity sample_entity_single_property_unindexed 100000 0.969% -0.019% 2.384%
counts reindex_after_adding_more_entities 0.946% 0.504% 1.410%
indexing with_query_results_indexed_multi-property_entities -0.896% -1.468% -0.371%
sample_entity sample_entity_single_property_indexed 1000 -0.861% -1.377% -0.400%
indexing query_people_multiple_individually_indexed_properties_entities 0.815% -0.051% 1.745%
indexing query_people_count_multiple_individually_indexed_properties_enti -0.768% -1.355% 0.129%
large_dataset bench_query_population_multi_indexed_entities 0.663% 0.220% 1.012%
indexing query_people_count_indexed_multi-property_entities -0.605% -1.449% 0.205%
sampling count_and_sampling_single_unindexed_concrete_plus_derived_entiti -0.544% -0.722% -0.364%
algorithm_benches algorithm_sampling_single_rand_reservoir -0.451% -0.831% -0.143%
counts index_after_adding_entities 0.397% 0.207% 0.579%
sample_entity sample_entity_multi_property_indexed 1000 0.361% 0.015% 0.620%
indexing with_query_results_multiple_individually_indexed_properties_enti 0.351% 0.139% 0.546%
algorithm_benches algorithm_sampling_multiple_l_reservoir -0.348% -0.963% 0.283%
large_dataset bench_query_population_multi_unindexed_entities -0.326% -0.543% -0.039%
large_dataset bench_query_population_property_entities 0.296% -0.064% 0.725%
sampling sampling_single_l_reservoir_entities -0.277% -0.923% 0.298%
algorithm_benches algorithm_sampling_single_known_length -0.217% -1.104% 0.668%
sample_entity sample_entity_whole_population 100000 0.205% -0.161% 0.689%
sample_entity sample_entity_whole_population 10000 -0.174% -0.609% 0.292%
sampling sampling_multiple_l_reservoir_entities 0.163% -0.057% 0.408%
counts single_property_unindexed_entities 0.160% -0.161% 0.596%
sampling sampling_single_unindexed_concrete_plus_derived_entities 0.115% 0.004% 0.230%
sample_entity sample_entity_multi_property_indexed 10000 -0.035% -0.406% 0.235%
counts multi_property_unindexed_entities 0.032% -0.443% 0.562%
sample_entity sample_entity_multi_property_indexed 100000 0.020% -0.243% 0.265%
sample_entity sample_entity_whole_population 1000 -0.011% -0.316% 0.437%
indexing query_people_single_indexed_property_entities 0.005% -0.052% 0.064%
Not Compared (no baseline yet)
Group Bench Reason
(none)

github-actions Bot added a commit that referenced this pull request May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

schedule!?

3 participants