Skip to content

perf(reindex): consume Found(t) from envelope probe to skip pre-t chain in LedgerState::load #1218

Open

Description

@aaj3f

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:

  1. first_t_where_graph_registered walks envelopes (byte-range get_range, ~128 KiB per commit) and returns GraphRegistrationProbe::Found(t) where t is the earliest commit at which the config graph was registered.
  2. The provider's Found(t) match arm logs t and falls through to LedgerState::load, which calls trace_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 at t' >= 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 LedgerState entry point (or modified existing one) that accepts the constraint shape from option A, B, or C.
  • ApiFulltextConfigProvider::resolve consumes the Found(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_absent but for the registered-config path: a CountingContentStore wrapper assertion that the per-commit full-blob get calls are bounded by the post-t chain, not the full chain.
  • The comment block at indexer_fulltext_provider.rs:108-119 is removed (the FUTURE OPTIMIZATION marker is consumed).

Out of scope

  • Pipelining the envelope walk in first_t_where_graph_registered itself (already on the deferred list elsewhere — separate issue).
  • Auditing other LedgerState::load callers (merge.rs, rebase.rs, ledger_info.rs) for similar stop-at-t opportunities (separate issue if undertaken).

References

Activity

  1. added
    P3
    area:storage
    on Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area:storage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions