Skip to content

chore: add startup-time plans#1004

Open
cdc-as81 wants to merge 2 commits into
mainfrom
cdc-as81-add-startup-plan
Open

chore: add startup-time plans#1004
cdc-as81 wants to merge 2 commits into
mainfrom
cdc-as81-add-startup-plan

Conversation

@cdc-as81

@cdc-as81 cdc-as81 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds startup-time plans: one-shot lifecycle work that runs at the
effective simulation start time—either the configured start time or 0.0
before regular plans.

  • Add Context::add_startup_plan and
    Context::add_startup_plan_with_phase.
  • Expose startup-plan scheduling through ContextBase and PluginContext.
  • Expand the event-loop state machine to model startup, regular execution,
    shutdown, and abort/resume transitions explicitly.
  • Add a dedicated startup queue with shared plan IDs, cancellation, and
    profiling support.
  • Update the Context API documentation to describe the full simulation
    lifecycle.

Behavior

Startup-time plans:

  • Run once at the effective simulation start time before any regular plan.
  • Follow ExecutionPhase ordering, then insertion order within each phase.
  • Yield to queued callbacks, which retain priority over plan selection.
  • May schedule additional startup-time plans while startup is still active.
  • Can be canceled through their PlanId.
  • Resume on a later execute call when startup is interrupted by abort.
  • Finish draining before shutdown proceeds when shutdown is requested during
    startup.
  • Panic if added after startup has completed.

github-actions Bot added a commit that referenced this pull request Jul 13, 2026

@RobertJacobsonCDC RobertJacobsonCDC left a comment

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.

The issue described how to expand the event loop state machine in a way that expands it to startup time. This implementation uses a separate state tracking mechanism that obfuscates which states and transitions are possible. If there is a reason, I need an explanation.

Also, don't let the LLM factor out single lines of code into useless helpers. Introducing DistinguishedQueue, add_distinguished_plan, and pop_next_distinguished is pretty egregious.

Comment thread src/plan_queue.rs Outdated
Comment thread src/plan_queue.rs Outdated
Comment thread src/context.rs Outdated
@cdc-as81
cdc-as81 force-pushed the cdc-as81-add-startup-plan branch from 010401a to 18a12e2 Compare July 14, 2026 14:08
@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.2 3.3 1.00
large_sir::baseline_households 3.3 ± 0.1 3.2 3.5 1.01 ± 0.02
large_sir::entities 7.8 ± 0.2 7.6 8.9 2.41 ± 0.07
large_sir::households 7.5 ± 0.2 7.3 8.2 2.30 ± 0.05

Criterion

Regressions (slower)
Group Bench Param Change CI Lower CI Upper
sample_entity sample_entity_single_property_unindexed 10000 7.523% 7.115% 8.059%
large_dataset bench_match_entity 5.139% 4.604% 5.863%
examples example-basic-infection 2.579% 1.867% 3.265%
counts reindex_after_adding_more_entities 1.315% 1.065% 1.591%
Improvements (faster)
Group Bench Param Change CI Lower CI Upper
indexing with_query_results_indexed_multi-property_entities -13.466% -14.264% -12.629%
large_dataset bench_filter_unindexed_entity -10.806% -13.938% -7.714%
sample_entity sample_entity_single_property_unindexed 1000 -10.004% -12.243% -7.497%
large_dataset bench_query_population_multi_unindexed_entities -9.883% -11.580% -8.084%
large_dataset bench_query_population_indexed_property_entities -7.938% -8.656% -7.279%
sampling sampling_single_unindexed_entities -5.111% -5.397% -4.808%
indexing query_people_count_indexed_multi-property_entities -4.826% -6.306% -3.086%
sample_entity sample_entity_multi_property_indexed 100000 -4.627% -5.222% -4.049%
indexing query_people_count_multiple_individually_indexed_properties_enti -4.444% -5.400% -3.681%
large_dataset bench_filter_indexed_entity -4.359% -6.291% -2.396%
sample_entity sample_entity_multi_property_indexed 1000 -4.323% -4.750% -3.926%
sample_entity sample_entity_single_property_indexed 1000 -4.318% -5.094% -3.568%
sample_entity sample_entity_multi_property_indexed 10000 -3.895% -4.392% -3.339%
large_dataset bench_query_population_multi_indexed_entities -3.863% -5.614% -2.261%
sample_entity sample_entity_single_property_indexed 10000 -3.621% -4.127% -2.977%
sampling sampling_multiple_unindexed_entities -3.149% -3.494% -2.789%
sampling count_and_sampling_single_known_length_entities -3.108% -3.567% -2.722%
sampling count_and_sampling_single_unindexed_concrete_plus_derived_entiti -2.823% -3.155% -2.553%
sample_entity sample_entity_whole_population 100000 -2.214% -2.788% -1.602%
sample_entity sample_entity_single_property_indexed 100000 -2.198% -2.712% -1.621%
indexing query_people_indexed_multi-property_entities -2.010% -2.333% -1.687%
sampling sampling_single_known_length_entities -1.970% -2.443% -1.521%
sampling sampling_multiple_l_reservoir_entities -1.821% -1.992% -1.662%
indexing query_people_multiple_individually_indexed_properties_entities -1.720% -2.371% -1.166%
algorithm_benches algorithm_sampling_multiple_l_reservoir -1.639% -2.119% -1.188%
Unchanged / inconclusive (CI crosses 0%)
Group Bench Param Change CI Lower CI Upper
indexing with_query_results_single_indexed_property_entities 2.136% 0.214% 4.005%
sample_entity sample_entity_whole_population 1000 -1.359% -2.034% -0.736%
sample_entity sample_entity_whole_population 10000 -1.299% -1.850% -0.703%
counts single_property_unindexed_entities 1.237% -0.212% 3.574%
counts multi_property_indexed_entities 1.085% 0.132% 2.209%
sampling sampling_single_l_reservoir_entities 1.064% 0.647% 1.382%
sample_entity sample_entity_single_property_unindexed 100000 -0.836% -1.176% -0.494%
algorithm_benches algorithm_sampling_multiple_known_length 0.779% 0.249% 1.292%
counts concrete_plus_derived_unindexed_entities -0.750% -1.505% -0.121%
large_dataset bench_query_population_property_entities -0.749% -1.444% -0.145%
large_dataset bench_query_population_derived_property_entities 0.428% -0.281% 1.105%
indexing query_people_count_single_indexed_property_entities 0.375% -0.472% 1.267%
counts single_property_indexed_entities -0.373% -1.115% 0.178%
sampling sampling_multiple_known_length_entities 0.304% -0.435% 0.818%
indexing with_query_results_multiple_individually_indexed_properties_enti -0.300% -0.595% -0.014%
indexing query_people_single_indexed_property_entities 0.293% -0.259% 0.738%
algorithm_benches algorithm_sampling_single_l_reservoir -0.289% -0.766% 0.188%
examples example-births-deaths 0.280% -0.050% 0.622%
sampling sampling_single_unindexed_concrete_plus_derived_entities -0.275% -0.450% -0.108%
algorithm_benches algorithm_sampling_single_known_length -0.202% -0.903% 0.537%
counts index_after_adding_entities -0.183% -0.414% 0.044%
counts multi_property_unindexed_entities -0.122% -0.980% 0.773%
algorithm_benches algorithm_sampling_single_rand_reservoir -0.122% -0.359% 0.063%
Not Compared (no baseline yet)
Group Bench Reason
(none)

github-actions Bot added a commit that referenced this pull request Jul 14, 2026
@cdc-as81

Copy link
Copy Markdown
Collaborator Author

The issue described how to expand the event loop state machine in a way that expands it to startup time. This implementation uses a separate state tracking mechanism that obfuscates which states and transitions are possible. If there is a reason, I need an explanation.

Also, don't let the LLM factor out single lines of code into useless helpers. Introducing DistinguishedQueue, add_distinguished_plan, and pop_next_distinguished is pretty egregious.

The separate startup-progress field is gone, and the lifecycle is now represented by a single explicit EventLoopStatus state machine. I also removed DistinguishedQueue, add_distinguished_plan, and pop_next_distinguished, and inlined the queue-specific logic. I added tests for abort and shutdown during startup, preserving pending shutdown across an abort, and single-step state transitions.

@CDCgov CDCgov deleted a comment from github-actions Bot Jul 14, 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.

Add add_startup_plan to be functionally symmetric to add_shutdown_plan

3 participants