Repository navigation
Description
Follow-up to #1391's reconciliation work. Base-presence probing makes the reconciled stats assemblies ~25× more expensive than the estimate lane, and every call re-probes from a cold cache. Measured at release: 10,008 flakes → 42.0ms (26.4×); 48,008 flakes → 204.2ms (25.1×).
The cost is confined to metadata surfaces (fluree info, apoc.meta.data, the db.* catalog shims) and is bounded by MAX_RECONCILED_NOVELTY_FLAKES, so nothing on the query hot path is affected. But the callers that hurt are exactly the repeating ones — a schema-introspection loop calling db.* or apoc.meta.data between commits pays the full probe cost every time.
Part 1 — an epoch-keyed shared probe cache
The precedent already exists: SchemaHierarchyCache (fluree-db-core/src/schema_hierarchy.rs:612) is a single-slot RwLock<Option<CacheEntry>> keyed (schema_t, schema_epoch), Arc-shared on LedgerState (fluree-db-ledger/src/lib.rs:146), with no explicit invalidation and carried across commits.
Cache the probe layer, not the assembled output — HashMap<BaseFactKey, Vec<BaseFact>> keyed (snapshot.t, novelty.epoch). Two properties make that the right layer, and both fail for an output cache:
- Probe results are independent of
to_t— reads are as-ofindexed_tagainst an empty overlay. That sidesteps the mismatch betweenmerged_stats'i64::MAXandledger_info'sledger.t(), which would otherwise force two cache entries for the same work. - They're policy-independent, so one cache safely serves
meta_data_rowsunder any enforcer. An output cache would have to key on the enforcer or risk serving one caller's policy-filtered counts to another.
Repeat calls then drop to estimate cost (~1.6–8.1ms at the measured window sizes). The test hook already exists: the scans stamp should read 0 on a second call and > 0 after a commit.
Part 2 — a predicate-presence skip
~10 lines, zero I/O: a predicate absent from indexed.properties cannot have base facts, because count includes history and aggregate_property_entries_from_graphs does no pruning — so absence means never indexed. An ns-split reconstruction false-miss degrades to probing, which is the safe direction.
Worth being honest that the win is smaller than it looks: a novelty-only-predicate probe already short-circuits inside the provider (a sid_to_p_id miss routes to overlay_only_flakes over the empty overlay, so no leaflet I/O). This shaves dictionary resolution, dispatch, and a Vec allocation — not disk. That fact belongs in the cap's cost documentation regardless of whether the skip lands.
Separate, and not addressed by either part
The first call after a commit still runs up to ~205ms of synchronous RangeProvider::range on a tokio worker, from inside async routes. A cache doesn't help the cold call. spawn_blocking around the sync assembly is the fix, and it's independent of everything above.
Credit to @bplatz, who worked out the cache design while reviewing #1699.
Activity