Files
tantivy/src
Luca Cominardi b64bc326a0 Memoize jitexpr value sources per input term ord
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
2026-11-02 16:17:02 +01:00
..
2026-06-01 14:39:44 +02:00
2026-10-07 11:47:25 +02:00
2026-09-16 23:39:47 +08:00
2026-08-31 14:40:27 +02:00
2024-10-22 09:26:54 +08:00
2026-09-16 23:39:47 +08:00