Repository navigation
Conversation
The per-parent-bucket maps created by prepare_max_bucket must stay lazy: there is one per parent bucket (up to the aggregation bucket limit), so a 65k-entry reservation each multiplied the memory by the parent cardinality and OOM'd on a two-level terms aggregation.
|
Closing: benchmarked this and the pre-size does not move the query. ClickBench, 100M docs / 16 splits / 1 node, Q33 =
The hint is the problem: The |
Summary
HashMapTermBucketsignored themap_init_valuecapacity hint, so high-cardinality terms aggregations grew the map through repeated rehashes. AddHashMapTermBuckets::with_capacity_hint(a cappedFxHashMap::with_capacity_and_hasherpre-size) and use it for the top-level hash-map branches ofbuild_segment_term_collector.Context
Found while profiling ClickBench Q33 on Quickwit:
hashbrownfallible_with_capacity9.37% +reserve_rehash9.25% +_rjem_je_large_ralloc30.21%.Two details shape the patch:
max_column_val + 1, which for the hash-map fallback is a raw column value (it can beu64::MAX), not the number of distinct terms.aggregation_bucket_limitbounds the entries actually kept, so the hint is capped at 65,536.TermAggregationMap::newis also called once per parent bucket byprepare_max_bucket, so pre-sizing there multiplies the reservation by the parent cardinality — that OOM'd a two-levelterms > termsaggregation in testing.newtherefore stays lazy.The aggregation memory guard is unchanged.
Test plan
cargo test -p tantivy aggregation