Skip to content

Comments

feat: Going turbofishing (adds the with! macro and implements query for entity ZSTs) #793

Open
k88hudson-cfa wants to merge 8 commits intomainfrom
k88-query-macro
Open

feat: Going turbofishing (adds the with! macro and implements query for entity ZSTs) #793
k88hudson-cfa wants to merge 8 commits intomainfrom
k88-query-macro

Conversation

@k88hudson-cfa
Copy link
Collaborator

@k88hudson-cfa k88hudson-cfa commented Feb 21, 2026

I'd actually argue we take out (or at least deprecate) the tuple syntax altogether and replace it with a macro/ZST (controversial I know)! My argument is that it's gets rid of the akward turbofish and trailing , when adding entities, sample_entity, and any other method that takes queries, and it's fairly natural to read.

Before After
let person: Person = context.add_entity(()) context.add_entity(Person)
context.add_entity::<Person, _>((Age(0),)) context.add_entity(with!(Person, Age(0)))
context.sample_entity::<Person, _, _>(Rng,(Alive(true),)) context.sample_entity(Rng, with!(Person, Alive(true))

We could do q! but I thought maybe we should add it later when we add other variants (like and, or) so we don't have a second breaking change. Wdyt?

I updated the docs but didn't take out the old tuple impl yet, I wanted to get thoughts first. Otherwise, it's ready for review

@github-actions
Copy link

Benchmark Results

Hyperfine

Command Mean [ms] Min [ms] Max [ms] Relative
large_sir::baseline 2.9 ± 0.0 2.8 3.0 1.00
large_sir::entities 12.0 ± 0.3 11.7 13.3 4.19 ± 0.13

Criterion

Regressions (slower)
Group Bench Param Change CI Lower CI Upper
sample_entity sample_entity_single_property_unindexed 10000 36.826% 35.558% 37.959%
indexing query_people_count_single_indexed_property_entities 16.814% 14.980% 18.595%
large_dataset bench_match_entity 9.162% 8.915% 9.403%
counts multi_property_unindexed_entities 5.524% 3.741% 7.431%
examples example-births-deaths 2.769% 2.471% 3.031%
counts index_after_adding_entities 1.412% 1.117% 1.644%
Improvements (faster)
Group Bench Param Change CI Lower CI Upper
indexing query_people_single_indexed_property_entities -17.236% -17.367% -17.142%
indexing query_people_indexed_multi-property_entities -8.418% -8.670% -8.128%
sample_entity sample_entity_whole_population 100000 -4.969% -5.267% -4.730%
sample_entity sample_entity_single_property_indexed 1000 -3.535% -3.754% -3.314%
sample_entity sample_entity_single_property_indexed 100000 -3.264% -4.059% -2.677%
sampling sampling_multiple_l_reservoir_entities -2.755% -3.027% -2.471%
sampling sampling_multiple_unindexed_entities -2.550% -2.924% -2.167%
sample_entity sample_entity_whole_population 10000 -2.034% -2.336% -1.645%
indexing with_query_results_multiple_individually_indexed_properties_enti -1.796% -2.364% -1.406%
sampling sampling_single_l_reservoir_entities -1.568% -1.643% -1.484%
Unchanged / inconclusive (CI crosses 0%)
Group Bench Param Change CI Lower CI Upper
counts single_property_unindexed_entities -2.319% -3.746% -0.966%
sample_entity sample_entity_single_property_indexed 10000 -1.375% -2.045% -0.545%
sample_entity sample_entity_whole_population 1000 1.214% 0.640% 1.963%
indexing query_people_multiple_individually_indexed_properties_entities 1.117% 0.667% 1.499%
sampling sampling_multiple_known_length_entities 0.997% 0.358% 1.544%
algorithm_benches algorithm_sampling_multiple_l_reservoir 0.955% 0.588% 1.290%
counts single_property_indexed_entities -0.880% -1.149% -0.640%
algorithm_benches algorithm_sampling_single_known_length 0.744% 0.217% 1.521%
large_dataset bench_query_population_derived_property_entities -0.693% -1.280% 0.030%
sample_entity sample_entity_multi_property_indexed 10000 -0.674% -1.001% -0.258%
indexing query_people_count_multiple_individually_indexed_properties_enti -0.598% -0.785% -0.385%
sample_entity sample_entity_multi_property_indexed 1000 0.592% -0.491% 2.359%
indexing query_people_count_indexed_multi-property_entities -0.560% -1.477% 0.325%
sample_entity sample_entity_single_property_unindexed 1000 -0.543% -1.068% -0.002%
counts multi_property_indexed_entities -0.523% -1.010% -0.174%
counts reindex_after_adding_more_entities 0.439% 0.209% 0.675%
sample_entity sample_entity_single_property_unindexed 100000 0.366% -0.387% 1.363%
large_dataset bench_query_population_property_entities -0.335% -0.834% 0.243%
sampling sampling_single_known_length_entities 0.289% -0.071% 0.692%
algorithm_benches algorithm_sampling_single_rand_reservoir -0.283% -0.573% -0.049%
large_dataset bench_filter_indexed_entity 0.249% -10.653% 13.819%
sample_entity sample_entity_multi_property_indexed 100000 -0.219% -0.454% 0.069%
algorithm_benches algorithm_sampling_single_l_reservoir 0.214% 0.040% 0.518%
sampling sampling_single_unindexed_entities 0.187% -0.060% 0.548%
indexing with_query_results_indexed_multi-property_entities 0.156% -0.289% 0.528%
indexing with_query_results_single_indexed_property_entities -0.149% -1.063% 0.750%
large_dataset bench_query_population_indexed_property_entities -0.119% -0.577% 0.226%
large_dataset bench_query_population_multi_unindexed_entities 0.112% -0.320% 0.633%
large_dataset bench_filter_unindexed_entity -0.071% -4.669% 4.911%
examples example-basic-infection -0.039% -1.359% 1.306%
algorithm_benches algorithm_sampling_multiple_known_length 0.029% -0.832% 1.134%
large_dataset bench_query_population_multi_indexed_entities 0.027% -0.225% 0.272%

github-actions bot added a commit that referenced this pull request Feb 21, 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.

1 participant