Repository navigation
Description
Background
PR #1211 fixed the indexing-Lambda first-reindex regression with two paired changes: an O(N log N) novelty bulk-load and an envelope-only short-circuit in ApiFulltextConfigProvider::resolve (commit 7c71297). Both are working in production — the regressing 787-commit ledger now reindexes in ~87s end-to-end, well under the 900s ceiling.
This issue tracks a follow-up optimization that surfaced in the review (review approval by @bplatz on PR #1211). It's purely a perf cleanup on the registered-config path; the no-config path that motivated #1211 is already fully optimized and unaffected by this work.
What's still suboptimal
When the config graph IS registered (i.e. customers who actually use f:fullTextDefaults configuration), ApiFulltextConfigProvider::resolve walks the DAG twice:
first_t_where_graph_registeredwalks envelopes (byte-rangeget_range, ~128 KiB per commit) and returnsGraphRegistrationProbe::Found(t)wheretis the earliest commit at which the config graph was registered.- The provider's
Found(t)match arm logstand falls through toLedgerState::load, which callstrace_commits_by_id(store, head, /* stop_at_t */ 0)and pulls the full blob of every commit, ignoring the fact that we already know config flakes can only live att' >= t.
For ledgers with config registered late in their history this means a full per-commit read_commit_v4 walk over commits we definitively know to contain no relevant flakes.
The relevant code lives at fluree-db-api/src/indexer_fulltext_provider.rs#L108-L119 — t is plumbed through the public GraphRegistrationProbe::Found(t) API surface, and a code comment at the consuming match arm preserves the future-use intent. What's missing is the downstream entry point on LedgerState to actually consume it.
Proposed implementations (pick one or sketch a third)
Option A — stop_at_t hint on LedgerState::load
Add a sibling entry point — e.g. LedgerState::load_with_stop_at_t(ns, ledger_id, backend, stop_at_t) — that threads a stop_at_t parameter all the way through to load_novelty's trace_commits_by_id(store, head, stop_at_t) call. The provider passes t - 1 (or t directly if we want inclusive semantics — verify against trace_commits_by_id's stop_at_t contract at fluree-db-core/src/commit.rs).
Pros: smallest diff. Reuses the existing load_novelty machinery. The novelty built will only contain commits at t' >= t, and since the config-graph IRI was first registered at t, all the flakes the resolver needs are present.
Cons: the resulting novelty is correct for resolving config but could be misleading if a future caller mistakes it for "all novelty since index_t". The new entry point's docstring needs to be sharp on this. Also: novelty still contains all graphs' flakes from t onward, when really we only need config-graph flakes — so memory is reduced but not minimal.
Option B — g_id-filtered novelty load
Add a Novelty::bulk_apply_commits_filtered(batches, reverse_graph, allow_g_ids) variant that drops flakes whose g_id isn't in the allowlist, paired with a LedgerState::load_for_graphs(ns, ledger_id, backend, &[CONFIG_GRAPH_ID]) entry point that wires it through.
Pros: the resulting novelty is minimal — only flakes for CONFIG_GRAPH_ID. Resolver's find_instances_of_type query touches the smallest possible overlay. Composes well with future "load this ledger but only graphs X, Y, Z" use cases (e.g. graph-source export).
Cons: larger surface area change. Touches fluree-db-novelty, fluree-db-ledger, and the API entry point. Needs a comparator/dedup correctness pass since the filtering happens before the dedup walk.
Option C — combine (filter + stop_at_t)
Most surgical. Apply both filters: walk only commits at t' >= t, AND retain only flakes for CONFIG_GRAPH_ID. Highest perf payoff for ledgers with config registered late in history; biggest design surface to land.
Lambda budget impact
Realistic ceiling for the saved cost: assume a ledger with 10k commits, config registered at commit 5k. The current registered-config path walks all 10k commits via read_commit_v4 (full blobs). With Option A we'd walk 5k. With Option B we'd still walk 10k but skip per-flake work for non-config graphs. With Option C we'd walk 5k AND skip non-config flakes. None of these are budget-blockers today (the 87s headline number was on a no-config ledger), but for any future customer that combines large chains with late-registered config this matters.
Acceptance criteria
- A new
LedgerStateentry point (or modified existing one) that accepts the constraint shape from option A, B, or C. ApiFulltextConfigProvider::resolveconsumes theFound(t)value at the match arm noted above instead of just logging it.- A regression test mirroring
it_reindex_pre_build_perf.rs::first_t_where_graph_registered_no_full_reads_when_iri_absentbut for the registered-config path: aCountingContentStorewrapper assertion that the per-commit full-blobgetcalls are bounded by the post-tchain, not the full chain. - The comment block at
indexer_fulltext_provider.rs:108-119is removed (the FUTURE OPTIMIZATION marker is consumed).
Out of scope
- Pipelining the envelope walk in
first_t_where_graph_registereditself (already on the deferred list elsewhere — separate issue). - Auditing other
LedgerState::loadcallers (merge.rs,rebase.rs,ledger_info.rs) for similar stop-at-t opportunities (separate issue if undertaken).
References
- PR Fix: Reindex Rebuild Performance Regression #1211 (merged at 7c71297)
- Comment block at
fluree-db-api/src/indexer_fulltext_provider.rs:108-119 GraphRegistrationProbe::Found(t)atfluree-db-core/src/commit.rs(search forpub enum GraphRegistrationProbe)LedgerState::load_noveltyatfluree-db-ledger/src/lib.rs(search forasync fn load_novelty)
Activity