mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-11-20 17:44:15 +00:00
A jitexpr value source evaluated its expression once per doc. For an expression of a text input, e.g. `(REGEXP_EXTRACT service "^([^-]+)" 1u64)`, the result only depends on the term of the doc, and text inputs are dictionary encoded with typically few distinct terms per segment (service names, hosts, statuses). Evaluating the expression per doc made a terms aggregation over such a calculated field ~100x slower than over the physical column; on a CloudPrem searcher, the expression accounted for 91% of the CPU of such a query. Memoize the results of an expression of a single text input whose dictionary has at most 65,536 terms, per input term ord. The expression is evaluated on the first doc of each term, and later docs read the encoded result from two dense arrays allocated zeroed when the source is opened (9 bytes per term), plus a slot for docs without a value. Terms are only resolved for the term ords evaluated for the first time. jitexpr functions are deterministic, and `Str` results are interned in the order of the docs as before, so the values and term ords are unchanged. `to_f64` clears the memo, whose results are encoded for the previous result type. Other expressions keep the per-doc path. benches/jitexpr_agg_bench.rs (2M docs, 4 segments, 200 services): terms on (REGEXP_EXTRACT service ..) 140.6 ms -> 7.7 ms (18x) terms on (UPPER service) 305.7 ms -> 8.0 ms (38x) terms on (REGEXP_EXTRACT request_id ..) 1.441 s -> 1.444 s (unique terms, no memo) terms on physical service 1.08 ms -> 1.07 ms