Skip to content

perf: specialize nth for unindexed property sources - #1037

Merged
RobertJacobsonCDC merged 1 commit into
RobertJacobsonCDC_705_query_profilingfrom
cdc-as81-query_profiling-nth
Aug 5, 2026
Merged

perf: specialize nth for unindexed property sources#1037
RobertJacobsonCDC merged 1 commit into
RobertJacobsonCDC_705_query_profilingfrom
cdc-as81-query_profiling-nth

Conversation

@cdc-as81

@cdc-as81 cdc-as81 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Implement ConcretePropertySource::nth directly.
  • Keep EntitySetIterator::nth unchanged.
  • Add test coverage for skipping through an unindexed property source.

Motivation

Unindexed single-property sampling uses Algorithm L, which repeatedly calls
Iterator::nth. Relying on the default trait implementation produced a
codegen-sensitive regression in the 10,000-entity benchmark.

Specializing nth on ConcretePropertySource preserves the same behavior while
stabilizing the hot path.

Benchmark results

Revision 10k median Change from main 100k change from main
main 4.931 µs
Before fix 6.557 µs +33.0% -2.4%
After fix 4.940 µs +0.2% -1.3%

The fix recovers over 99% of the lost 10k performance while retaining the 100k
improvement.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Benchmark Results

Hyperfine

Command Mean [ms] Min [ms] Max [ms] Relative
large_sir::baseline 3.6 ± 0.2 3.4 4.2 1.00 ± 0.08
large_sir::baseline_households 3.5 ± 0.1 3.4 4.1 1.00
large_sir::entities 8.1 ± 0.3 7.6 9.2 2.28 ± 0.12
large_sir::households 8.1 ± 0.7 7.6 11.1 2.27 ± 0.22

Criterion

Regressions (slower)
Group Bench Param Change CI Lower CI Upper
indexing with_query_results_indexed_multi-property_entities 75.367% 74.498% 76.092%
sample_entity sample_entity_single_property_unindexed 10000 23.152% 21.125% 25.037%
counts reindex_after_adding_more_entities 10.910% 10.577% 11.235%
large_dataset bench_match_entity 6.791% 6.589% 6.996%
indexing query_people_indexed_multi-property_entities 4.408% 3.893% 4.901%
counts index_after_adding_entities 3.650% 3.413% 3.860%
indexing query_people_count_indexed_multi-property_entities 2.838% 2.530% 3.152%
indexing query_people_multiple_individually_indexed_properties_entities 2.512% 2.332% 2.693%
indexing with_query_results_multiple_individually_indexed_properties_enti 2.316% 2.033% 2.546%
examples example-births-deaths 2.156% 1.369% 3.232%
sampling sampling_single_known_length_entities 1.890% 1.519% 2.236%
sampling count_and_sampling_single_unindexed_concrete_plus_derived_entiti 1.505% 1.410% 1.603%
Improvements (faster)
Group Bench Param Change CI Lower CI Upper
large_dataset bench_query_population_multi_indexed_entities -36.691% -37.846% -35.388%
counts multi_property_indexed_entities -23.146% -23.744% -22.516%
sample_entity sample_entity_single_property_unindexed 1000 -18.283% -18.771% -17.863%
sample_entity sample_entity_single_property_indexed 100000 -7.943% -8.933% -6.935%
sampling sampling_multiple_unindexed_entities -3.727% -3.873% -3.605%
examples example-basic-infection -3.686% -4.007% -3.371%
large_dataset bench_query_population_derived_property_entities -3.327% -4.125% -2.419%
large_dataset bench_query_population_indexed_property_entities -3.186% -4.024% -2.357%
sample_entity sample_entity_whole_population 100000 -2.069% -2.747% -1.498%
sample_entity sample_entity_single_property_indexed 1000 -1.663% -2.116% -1.234%
indexing query_people_count_single_indexed_property_entities -1.610% -1.864% -1.355%
sampling sampling_single_l_reservoir_entities -1.401% -1.703% -1.134%
counts multi_property_unindexed_entities -1.318% -1.665% -1.029%
Unchanged / inconclusive (CI crosses 0%)
Group Bench Param Change CI Lower CI Upper
indexing query_people_single_indexed_property_entities 1.988% -0.512% 4.422%
indexing query_people_count_multiple_individually_indexed_properties_enti 1.385% 0.410% 2.060%
sample_entity sample_entity_multi_property_indexed 1000 -1.370% -1.815% -0.886%
sample_entity sample_entity_whole_population 1000 1.339% 0.694% 2.061%
sampling sampling_single_unindexed_concrete_plus_derived_entities 1.160% 0.827% 1.497%
sampling sampling_multiple_l_reservoir_entities -1.135% -1.431% -0.830%
sampling sampling_multiple_known_length_entities 1.056% 0.665% 1.622%
large_dataset bench_query_population_multi_unindexed_entities -0.938% -1.442% -0.576%
sample_entity sample_entity_single_property_indexed 10000 0.875% -0.038% 1.882%
counts single_property_indexed_entities 0.843% 0.319% 1.337%
indexing with_query_results_single_indexed_property_entities -0.732% -1.122% -0.263%
sample_entity sample_entity_multi_property_indexed 100000 -0.654% -1.108% -0.166%
sampling sampling_single_unindexed_entities 0.625% 0.348% 0.870%
large_dataset bench_filter_indexed_entity -0.579% -2.275% 1.144%
sample_entity sample_entity_multi_property_indexed 10000 -0.579% -1.109% -0.058%
sample_entity sample_entity_single_property_unindexed 100000 0.563% 0.242% 0.813%
sampling count_and_sampling_single_known_length_entities 0.518% 0.233% 0.802%
large_dataset bench_filter_unindexed_entity -0.386% -3.805% 3.395%
large_dataset bench_query_population_property_entities -0.313% -0.789% 0.291%
counts concrete_plus_derived_unindexed_entities 0.238% -0.382% 0.966%
algorithm_benches algorithm_sampling_multiple_known_length 0.206% -0.207% 0.722%
algorithm_benches algorithm_sampling_single_l_reservoir -0.201% -0.405% -0.014%
algorithm_benches algorithm_sampling_single_known_length 0.176% -0.487% 0.782%
counts single_property_unindexed_entities -0.137% -0.452% 0.112%
sample_entity sample_entity_whole_population 10000 0.114% -0.146% 0.354%
algorithm_benches algorithm_sampling_single_rand_reservoir -0.090% -0.275% 0.063%
algorithm_benches algorithm_sampling_multiple_l_reservoir -0.018% -0.367% 0.313%
Not Compared (no baseline yet)
Group Bench Reason
(none)

@RobertJacobsonCDC
RobertJacobsonCDC merged commit a85155f into RobertJacobsonCDC_705_query_profiling Aug 5, 2026
21 checks passed
@RobertJacobsonCDC
RobertJacobsonCDC deleted the cdc-as81-query_profiling-nth branch August 5, 2026 16:20
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.

3 participants