Skip to content

Fix: Reindex Rebuild Performance Regression - #1211

Merged
aaj3f merged 5 commits into
mainfrom
fix/reindex-pre-build-perf-regression
May 4, 2026
Merged

aaj3f merged 5 commits into
mainfrom
fix/reindex-pre-build-perf-regression

Conversation

@aaj3f

@aaj3f aaj3f commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Fixes the regression that pushed first-time reindex on the large dataset indexing Lambda past the 13-minute waiter timeout repeatedly. Two stacked slowdowns were hitting any reindex of a ledger with no prior index; this PR addresses both, plus a defensive fix for branched ledgers and regression guards so neither can re-emerge silently.

Background

CloudWatch logs for a particular indexing lambda showed 787-commit reindexes of a dataset consistently timing out at 13 minutes:

  • 24-30s of preamble (then silence in the default INFO log filter)
  • 1574 = 2 × 787 read_commit_v4 debug events when DEBUG was bumped
  • 11+ minutes of total silence after that — no Phase A/B/C/D progress
  • Repeated Index trigger timed out waits, identical retry pattern across cold starts

Two distinct regressions, both shipped via PR #1199 / commit 5985d0f01 fluree v4 baseline:

  1. Novelty::apply_commit called per-commit during LedgerState::load_novelty. The merge_batch_into_index two-way merge accrued O(M·N̄) over the chain. For 787 commits × ~9k ops this measured ~11 minutes on Lambda single-vCPU. Silent in logs because apply_commit's span lives in fluree_db_novelty, not in any rebuild target most filters include.

  2. ApiFulltextConfigProvider::resolve always loaded full LedgerState. Even when the ledger had never written f:LedgerConfig, resolve walked every commit via load_commit_by_id (read_commit_v4) just to discover the config graph was empty. ~30s of wasted full-blob reads + zstd decompresses + flake construction before the rebuild even started.

The provider regression originated in fluree/db-r commit 4d6ff8fc "fulltext fixes/enahnce" on the unmerged misc/fixes branch (a fix for the "Solo bug report 2026-04-23" referenced in fluree-db-api/tests/it_query_fulltext.rs:863-868). The novelty regression has been there longer but only surfaced once the provider started forcing it on every reindex.

BranchedContentStore separately doesn't implement get_range, so PR fluree/db-r#158's envelope-only byte-range probe falls back to full-blob fetch via the trait default for branched ledgers. The dataset-in-question's main branch isn't branched so this isn't the blocking cause for them, but it's a regression vector waiting for the next branched ledger reindex.

Changes

Novelty::bulk_apply_commits (commit 1, 51217f33b)

fluree-db-novelty/src/lib.rs — new bulk path designed for first-load / catch-up. One ingest pass routes flakes per-graph, parallel sort by identity-then-t, linear set-semantics dedup walk (matches apply_commit's fact_currently_asserted_in_graph skip rule for assertions; always keeps retractions), then four parallel sorts to build SPOT/PSOT/POST/OPST. O(N log N) total regardless of commit count.

fluree-db-ledger/src/lib.rs::load_novelty — switches the deferred-batch replay loop from per-commit apply_commit to a single bulk_apply_commits call. dict-novelty population still runs per-batch in commit order so overlay translation invariants are preserved.

Range-aware BranchedContentStore (commit 1, 51217f33b)

fluree-db-core/src/storage.rs — implements ContentStore::get_range on BranchedContentStore. Mirrors get's ancestry-fallback semantics, calling get_range natively on each ancestor so range-capable backends keep their byte-range optimization across the entire chain.

Envelope-only short-circuit (commit 2, d5e03c27d)

fluree-db-core/src/commit.rs — surfaces graph_delta on the public CommitEnvelope (the binary envelope already encoded it; the v4 reader was dropping it on the floor). Adds new public helper first_t_where_graph_registered<C: ContentStore>(store, head, iri) that walks the DAG via load_commit_envelope_by_id (byte-range ~128 KiB per envelope) and returns the lowest t where iri appears in any commit's graph_delta, or None if it never does. v3 chains return None (v3 envelopes never carried graph_delta) — callers fall through to a full load on None.

fluree-db-api/src/indexer_fulltext_provider.rs::resolve — runs the envelope-only probe before LedgerState::load. If config_graph_iri(ledger_id) is never registered in any commit's graph_delta, returns an empty configured-properties list immediately. No LedgerState::load, no novelty build, no full commit reads. If the IRI is found, falls through to the existing load + resolve_ledger_config path — which is itself fast now thanks to bulk_apply_commits.

Regression tests (commit 3)

fluree-db-api/tests/it_reindex_pre_build_perf.rs (new):

  • first_t_where_graph_registered_no_full_reads_when_iri_absent — deterministic CountingContentStore test asserting the envelope walk uses only get_range, never get, when the target IRI is missing.
  • first_t_where_graph_registered_returns_lowest_t_when_iri_present — confirms the helper finds the earliest registration t.
  • orchestrator_first_reindex_no_config_completes_quickly — end-to-end orchestrator-path reindex of a 200-commit no-config ledger via BackgroundIndexerWorker matching the AWS Lambda wiring (with_fulltext_config_provider), with a 60s wall-clock budget far below the 13-minute Lambda waiter that motivated the fix.

Effect on the original reindex scenario

Pre-fix (CloudWatch evidence, requestId 6e44e74e-1c8e-411b-a8b7-b73d8b268db8, cold start 2026-04-30T16:21:35):

  • LedgerState::load_novelty walked all 787 commits via read_commit_v4 in 29s
  • apply_commit × 787 in O(N²) replay then ran for 11+ minutes silently
  • Lambda waiter timed out at 13 minutes
  • Lambda function timed out at 15 minutes before any rebuild progress

Post-fix (projected from in-process timings + Lambda ratios):

  • Envelope-only probe — ~787 byte-range reads, ~5-8s end-to-end on Lambda
  • first_t_where_graph_registered returns None. It has no f:LedgerConfig — verified via DynamoDB query of nameservice, where pk=dataset:main, sk=config shows config_v: 0 and no config_id field.
  • ApiFulltextConfigProvider::resolve returns Vec::new() immediately. No LedgerState::load, no novelty build.
  • Rebuild proceeds normally — Phase A 31s, Phase B ~10s with K=3, Phase C tiny, Phase D 12s. Total reindex 60-90s, well under 900s.

For ledgers with config in commits (test path fulltext_configured_property_first_build_via_provider, fulltext_configured_property_picked_up_by_build_index_for_ledger, etc.), the envelope walk falls through to the full load path — which is now fast thanks to bulk_apply_commits. Behavior unchanged from a correctness standpoint.

Diagnosis methodology

Iteratively bumped Lambda RUST_LOG across cold starts to localize the silent stretch:

  1. INFO baseline — only orchestrator + waiter messages visible, the 13-minute stretch invisible.
  2. info,fluree_db_indexer=debug,fluree_db_core::commit=debug,... — surfaced the 1574 = 2 × 787 read_commit_v4 events, bounded the catch-up at 29s. Span tag name:"load_commit" on every event traced the calls to load_commit_by_id.
  3. Code audit (fluree-db-indexer/src/lib.rs:122-126 → fluree-db-api/src/indexer_fulltext_provider.rs:43-82 → fluree-db-ledger/src/lib.rs::load_novelty:284) located both regressions.
  4. DynamoDB inspection of the symptomatic NsRecord confirmed config_id: None, validating the envelope-short-circuit fast path.

Audit of the proposed fix by an independent agent caught one early incorrect direction (skipping the provider on index_head_id.is_none() would have silently broken config-via-commits on first build, failing fulltext_configured_property_first_build_via_provider). The final shape preserves correctness for that path while still avoiding the slow walk for no-config ledgers.

Test plan

  • cargo fmt --all -- --check passes
  • cargo clippy --workspace --all-features --all-targets -- -D warnings passes
  • cargo nextest run --workspace --all-features --no-fail-fast — 6014/6014 tests pass (11 skipped — feature-gated S3 testcontainers paths run separately)
  • Existing fulltext_configured_property_first_build_via_provider and friends still pass — confirms config-via-commits fulltext path on first reindex is preserved
  • Existing it_rebuild_fetch_counts.rs still passes — confirms Phase A/B fetch contract from PR Allow clj api to work with closed api ledger #158 is preserved
  • Existing it_indexing_workflow.rs passes — confirms orchestrator + manual-trigger paths unchanged
  • New it_reindex_pre_build_perf.rs: first_t_where_graph_registered_no_full_reads_when_iri_absent, first_t_where_graph_registered_returns_lowest_t_when_iri_present, orchestrator_first_reindex_no_config_completes_quickly
  • Lambda smoke test on original dataset — after this PR merges and the indexing Lambda redeploys, confirm the reindex completes well under 900s

Notes

Read-path only on the BranchedContentStore change. No on-disk format changes. CommitEnvelope::graph_delta is a new public field, but the binary encoding already carried it — only the v4 reader surfaced it on the public type.

v3 chains never encoded graph_delta on the envelope and will always return None from first_t_where_graph_registered. Callers that need v3 compatibility should fall back to a full load on None, which ApiFulltextConfigProvider already does.

Out of scope, follow-up candidates:

  • Parallelize the envelope walk in first_t_where_graph_registered via buffered(K) for very long chains.
  • Extend the orchestrator to expose its content store for test instrumentation so the wall-clock budget test can also assert fetch counts deterministically.
  • Audit other LedgerState::load callers (merge.rs:543, rebase.rs:348, ledger_info.rs:539) for similar slow-path opportunities now that the bulk-load infrastructure exists.

aaj3f added 3 commits April 30, 2026 15:20
Two paired fixes that together unblock first-time reindex on lambdas
where a long commit chain forces `LedgerState::load` to walk every
commit before the rebuild can start.

## What's wrong

`LedgerState::load_novelty` walks the full chain via `trace_commits_by_id`
and replays each commit's flakes through `Novelty::apply_commit`. That
per-commit path runs an LSM-style two-way merge per index (4 indexes ×
M commits) — `O(target.len() + batch.len())` per merge accruing to
`O(M·N̄)` over the chain. For a 787-commit production ledger with ~9k
ops/commit this measured at ~13 minutes on a 10 GB single-vCPU lambda,
exceeding the 900s reindex ceiling. The hang was silent because
`apply_commit`'s progress emit lives in `fluree_db_novelty` (not in any
rebuild log target), so cloudwatch saw 11+ minutes of nothing between
`Loaded ledger state for queued indexing work` and a timeout — masking
which phase was at fault.

`BranchedContentStore` (`fluree-db-core/src/storage.rs`) implemented
`get`, `has`, `put`, etc., but **not** `get_range`. The trait default
falls back to `get` + slice. Branched ledgers therefore silently
nullify PR #158's envelope-only byte-range probe in
`load_commit_envelope_by_id` — every Phase A envelope read becomes a
full-blob fetch. The blocking production case here is non-branched so
this isn't its proximal cause, but it's a regression vector waiting
for the next branched ledger reindex.

## What changes

`fluree-db-novelty/src/lib.rs` — adds `Novelty::bulk_apply_commits`:

- Routes every flake into a per-graph bucket in one ingest pass.
- Sorts each graph by an identity-then-t key (`s, p, o, dt, m, t, op`)
  via `par_sort_unstable_by`.
- Walks each `(s, p, o, dt, m)` group linearly to apply set semantics
  — drops an assertion only when the prior kept flake for the same
  identity was also an assertion (mirrors `apply_commit`'s
  `fact_currently_asserted_in_graph` skip rule); always keeps
  retractions.
- Re-sorts the deduped set into the 4 index orders (SPOT/PSOT/POST/OPST)
  once each.

Total work is `O(N log N)` regardless of how many commits the chain
contains. For the 787-commit case this drops the catch-up from minutes
to under ten seconds on lambda. Existing graph contents are merged
into the dedup pass alongside the new batches so the post-condition
matches what a sequential per-commit `apply_commit` chain would have
produced. `epoch` bumps once per call.

Helper functions `cmp_object`, `cmp_meta`, and `same_identity` mirror
`fluree_db_core::comparator`'s private comparators so the dedup walk
groups by exactly the same `(s, p, o, dt, m)` identity that
`apply_commit` checks. They're file-local — no public API surface
added beyond the new method itself.

`fluree-db-ledger/src/lib.rs::load_novelty` — switches the
deferred-batch replay loop from per-commit `apply_commit` to a single
`bulk_apply_commits` call. The dict-novelty population still runs
per-batch in commit order so overlay translation invariants are
preserved before the bulk apply.

`fluree-db-core/src/storage.rs` — implements `ContentStore::get_range`
on `BranchedContentStore`. Mirrors the `get` semantics: try the
branch's own store first, fall through to ancestor stores on
`NotFound`. Crucially calls `get_range` on each ancestor (not the
trait default fallback), so range-capable backends keep their byte-
range optimization across the entire branch ancestry.

## Verification

- `cargo check -p fluree-db-core -p fluree-db-novelty -p fluree-db-ledger`
  passes.
- `cargo nextest run -p fluree-db-novelty -p fluree-db-ledger
--no-fail-fast` — 62/62 pass, including the existing set-semantics
  tests (`test_apply_commit_skips_duplicate_assertions_across_commits`,
  `test_apply_commit_allows_reassert_after_retract`,
  `test_apply_commit_does_not_dedup_distinct_metadata`,
  `test_per_graph_isolation`) which exercise the dedup invariants
  `bulk_apply_commits` is required to preserve.

End-to-end lambda validation + multi-commit perf regression test land
in the next commits in this branch (orchestrator-path test asserting
wall-clock budget + a streaming envelope-aware
`ApiFulltextConfigProvider` that skips full novelty load when only
the config graph is needed).
Skips `LedgerState::load`'s full chain walk in
`ApiFulltextConfigProvider::resolve` when the ledger has never
registered the config graph IRI. This is the common case on a
first-ever reindex of a ledger that hasn't set up `f:fullTextDefaults`
— for the regressing 787-commit production ledger this PR is built
against, it removes ~30s of full-blob commit reads, zstd decompresses,
and flake construction that the resolver was performing only to
discover an empty config graph.

## What's wrong

`ApiFulltextConfigProvider::resolve` always called `LedgerState::load`,
which walks the entire commit chain via `trace_commits_by_id` and
fully decodes every commit blob (`read_commit_v4`). Even with the
preceding `bulk_apply_commits` work making the in-memory replay
`O(N log N)` instead of `O(N²)`, that approach still pays per-commit
S3 fetch + decompress + decode regardless of whether any config flake
will be found.

For ledgers that never wrote `f:LedgerConfig` — which the regressing
production deployment had never done — that's pure waste. There is no
fulltext config to discover, yet every reindex re-walks the chain and
re-builds a complete novelty just to run a SPARQL pattern over a graph
slot that has no triples.

## What changes

`fluree-db-core/src/commit.rs` — adds `graph_delta` to the public
`CommitEnvelope` struct. The binary envelope already encodes
`graph_delta` (per `codec/envelope.rs:182`), but the v4 envelope
reader was dropping it on the floor. Surfacing it on the public
`CommitEnvelope` lets envelope-only walkers detect that a particular
named graph has been registered without paying for ops decode. The v3
legacy reader returns an empty `graph_delta` since v3 never encoded
this field — callers that rely on the short-circuit and may face v3
chains should fall through to a full load on `None`.

`fluree-db-core/src/commit.rs` — adds
`first_t_where_graph_registered<C: ContentStore>(store, head, iri)`.
Walks the commit DAG using `load_commit_envelope_by_id` (byte-range
~128 KiB per commit on range-capable backends, no zstd, no flake
construction), inspects each envelope's `graph_delta` for the IRI,
and returns the lowest `t` where it's seen — or `None` if it never
appears. Re-exported from the crate root.

`fluree-db-api/src/indexer_fulltext_provider.rs::resolve` — runs the
envelope-only probe before doing anything else:

1. Look up the `NsRecord` (one nameservice round-trip).
2. If `commit_head_id` is set, build the appropriate content store
   (branched if `source_branch` is set, flat otherwise — same shape
   `LedgerState::load` would have built internally).
3. Call `first_t_where_graph_registered(cs, head, config_graph_iri(ledger_id))`.
4. If `None`: log a debug breadcrumb, return an empty configured-
   properties list. **No `LedgerState::load`, no novelty build, no
   full commit reads.**
5. If `Some(_)`: log the registration `t` and fall through to the
   existing `LedgerState::load` + `resolve_ledger_config` path,
   which is itself fast now thanks to `bulk_apply_commits`.

The provider's lookup-then-probe ordering avoids racing with
nameservice updates and re-uses the existing
`fluree_db_nameservice::build_branched_store` helper so branched
ledgers see the same ancestry walk that `LedgerState::load` would
have set up.

## Effect on the failing scenario

Affected production reindex (787 commits, `config_id: None`, no
`f:fullTextDefaults` ever committed):

- Before: ~30s of full commit blob reads in `LedgerState::load_novelty`
  via `load_commit_by_id`/`read_commit_v4`, plus the now-O(N log N)
  novelty build, before the rebuild even starts.
- After: ~787 byte-range envelope probes (each 128 KiB or less; on
  S3 these are sub-100 ms RTT), then `first_t_where_graph_registered`
  returns `None`, then resolve returns immediately. End-to-end well
  under 10s on lambda for the entire pre-rebuild step.

For ledgers that DO use fulltext config (e.g.
`fulltext_configured_property_first_build_via_provider` test), the
envelope walk finds the registration and the existing path proceeds
unchanged — but now backed by `bulk_apply_commits`, so the slow path
is also fast.

## Verification

- `cargo check -p fluree-db-core -p fluree-db-api` passes.
- `cargo nextest run -p fluree-db-api --test it_query_fulltext
--no-fail-fast` — 13/13 pass, including
  `fulltext_configured_property_first_build_via_provider`,
  `fulltext_configured_property_picked_up_by_build_index_for_ledger`,
  `fulltext_configured_property_indexed_after_reindex`,
  `fulltext_configured_incremental_adds_to_arena`,
  `fulltext_configured_two_commits_two_values_full_rebuild`,
  `fulltext_configured_langtagged_literal_scores_via_arena`. These
  exercise the path where the config graph IS registered (envelope
  walk falls through to full load) and assert the configured
  properties are still picked up correctly.

End-to-end lambda validation + a multi-commit orchestrator-path
regression test with a wall-clock budget land in the next commit.
Adds an integration test crate covering both fixes shipped earlier on
this branch (`51217f33b` novelty bulk-load + `d5e03c27d` envelope
short-circuit). The audit explicitly called out missing regression
tests as the gap that let the per-commit `apply_commit` regression
ship undetected — these tests close that gap.

## Tests

`fluree-db-api/tests/it_reindex_pre_build_perf.rs` (new):

1. **`first_t_where_graph_registered_no_full_reads_when_iri_absent`**
   Deterministic counting test using a `CountingContentStore`
   wrapper. Seeds 8 commits with no config-graph data, runs the new
   `first_t_where_graph_registered` helper looking for the config IRI,
   asserts:
   - return is `None` (IRI never registered),
   - `get` calls == 0 (NO full-blob fetches),
   - `get_range` calls == 8 (one envelope read per commit).
     Any future change that reintroduces a full-blob walk through
     `load_commit_by_id` (the pre-fix shape) flips `get` non-zero and
     fails the test loudly. Mirrors the structure of
     `it_rebuild_fetch_counts.rs` so the convention for fetch-count
     regression guards stays uniform.

2. **`first_t_where_graph_registered_returns_lowest_t_when_iri_present`**
   Confirms the helper actually finds the registration. Writes a
   `f:LedgerConfig` triple in the genesis commit, then 4 follow-up
   non-config commits. Asserts the helper returns `Some(1)` — proving
   the envelope walk surfaces the earliest registration regardless of
   later commits.

3. **`orchestrator_first_reindex_no_config_completes_quickly`**
   End-to-end smoke test of the orchestrator path with the AWS
   wiring shape: `BackgroundIndexerWorker` started on a `LocalSet`,
   `IndexerConfig::small().with_fulltext_config_provider(...)`
   matching `start_background_indexing_dyn`. Seeds 200 commits on a
   no-config ledger, triggers via `IndexerHandle::trigger`, waits for
   `IndexOutcome::Completed`, asserts `index_t == 200` and wall-clock
   under 60s.

   Wall-clock budgets are necessarily soft on CI, but a regression
   in either fix would push this past the budget on Lambda
   single-vCPU and produce clearly-elevated runtime even on
   multi-core CI hardware. The 60s ceiling is well below the 13-min
   Lambda waiter timeout that motivated this branch — far enough
   from the noise floor to catch egregious reintroduction of the
   per-commit `O(N²)` novelty replay or the full
   `LedgerState::load` chain walk on no-config ledgers.

## Verification

- `cargo fmt --all -- --check` — clean.
- `cargo clippy --workspace --all-features --all-targets -- -D warnings`
  — clean.
- `cargo nextest run --workspace --all-features --no-fail-fast` —
  6014/6014 tests pass (11 skipped — feature-gated S3
  testcontainers paths that are run separately). Includes the 3 new
  tests in `it_reindex_pre_build_perf.rs` plus the existing
  `it_rebuild_fetch_counts.rs`,
  `fulltext_configured_property_first_build_via_provider`,
  `it_indexing_workflow.rs`, and the broader workspace coverage
  unaffected by the changes on this branch.
@aaj3f
aaj3f force-pushed the fix/reindex-pre-build-perf-regression branch from 789f00b to 870f75f Compare April 30, 2026 19:22
…y contract

Addresses review items 1, 2, 5, and 7 on PR #1211. The v3 fix is
correctness-blocking; the others are inexpensive hardening bundled into
the same commit so the branch doesn't churn.

## Item 1 — v3 chains no longer silently lose fulltext config (correctness)

Reviewer flagged that `first_t_where_graph_registered` returned `None`
on v3 envelopes — which never encoded `graph_delta` — so a chain
containing any v3 commit (mixed v3-then-v4 chains, or pure v3 chains)
caused `ApiFulltextConfigProvider::resolve` to short-circuit and
silently report no configured fulltext properties even when the config
graph WAS registered. The PR description claimed v3 callers fell
through to a full load; the code did not.

**Change:** the helper now returns a tri-state
`GraphRegistrationProbe { Found(t) | NotFound | Inconclusive }`. It
inspects each envelope's blob version byte (header byte 4) before
trusting the decoded `graph_delta`. Any v3 (or unknown future
version) flips the result to `Inconclusive`, which the provider
treats identically to `Found(_)`: fall through to
`LedgerState::load`. Only `NotFound` short-circuits.

The version inspection reuses the bytes already fetched for envelope
decode — no extra round trips. Implementation factors the existing
`load_commit_envelope_by_id` body into a private
`load_commit_envelope_with_version` sibling that returns
`(envelope, version)`; the public function is a thin wrapper that
discards the version, so existing callers (CLI sync, merge, rebase,
etc.) are unaffected.

New regression test in `legacy_v3::tests`:
`first_t_where_graph_registered_returns_inconclusive_on_v3_envelope`
constructs a v3 blob via the existing `build_v3_test_blob` helper,
puts it in a `MemoryContentStore`, runs the probe, and asserts
`Inconclusive`. Locks in the contract that no future "simplification"
can collapse v3 detection back into the `NotFound` path.

## Item 2 — Document `bulk_apply_commits` arena bloat semantics

Reviewer noted that `bulk_apply_commits` pushes flakes into the
`FlakeStore` arena before the dedup walk, leaving deduped duplicates
in the arena and inflating `self.size` for the lifetime of the
`Novelty`. Unlike `apply_commit` which dedupes BEFORE
`push_with_size`. For the only call site (`load_novelty` from a fresh
empty arena consumed and dropped immediately) this bloat is bounded
and operationally negligible — but the contract is not the same as
`apply_commit`'s and any future caller should know.

**Change:** doc-comment block on `Novelty::bulk_apply_commits`
explicitly contrasts the arena retention with `apply_commit`,
describes the bound at the design call site, and warns against
hot-path mutation use without redesigning the dedup or adding a
post-walk arena rebuild.

## Item 5 — Document `first_t_where_graph_registered` cost contract

Reviewer noted the helper walks the full DAG even after a hit so it
can return the smallest `t` across alternate parent branches. Correct
as written; just unstated in the docstring.

**Change:** added a "Cost contract" section explaining why the walk
is exhaustive and noting that pipelining via `buffered(K)` is a
follow-up optimization (already on the PR's deferred list).

## Item 7 — Drift-guard test for novelty's local comparator helpers

Reviewer noted `cmp_object`, `cmp_meta`, and `same_identity` are
file-local copies of `fluree_db_core::comparator`'s private helpers,
with no compile-time pin keeping them aligned. Silent drift would
produce silently-dropped or duplicated assertions during first-load
catch-up — extremely hard to diagnose at runtime.

**Change:** new unit test
`local_identity_helpers_match_core_spot_comparator_semantics` in
`fluree-db-novelty::tests`. Constructs flake pairs that share or
differ on each `(s, p, o, dt, m)` component plus the `(t, op)` tail,
asserts `same_identity` agrees with `IndexType::Spot.compare`'s
prefix behavior on every dimension, and verifies `cmp_meta` /
`cmp_object` ordering matches what SPOT encodes. If either side ever
drifts, the test fires loudly.

## Verification

- `cargo fmt --all -- --check` clean.
- `cargo clippy --workspace --all-features --all-targets -- -D warnings`
  clean.
- `cargo nextest run --workspace --all-features --no-fail-fast` —
  6016/6016 tests pass (up from 6014: +1 v3 fallthrough test, +1
  comparator drift-guard test). 11 skipped (feature-gated S3
  testcontainers paths run separately).
- All three existing `it_reindex_pre_build_perf.rs` tests continue
  to pass; the no-config and with-config tests now use
  `GraphRegistrationProbe::NotFound` / `Found(t)` directly instead
  of `Option`.

## Deferred (review items 3, 4, 6, 8, 9)

Item 3 (duplicate NS lookup + branched-store build on the
registered-config path) — bounded perf cleanup, no Lambda budget
exposure. Deferred to follow-up.

Item 4 (cosmetic), item 6 (already correct), items 8 and 9 (positive
feedback) — no action required
@aaj3f aaj3f changed the title Fix/reindex pre build perf regression Fix: Reindex Rebuild Performance Regression Apr 30, 2026
@aaj3f
aaj3f requested review from bplatz and zonotope and removed request for bplatz April 30, 2026 20:24
@aaj3f
aaj3f marked this pull request as ready for review April 30, 2026 20:24

@bplatz bplatz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the config graph IS registered, ApiFulltextConfigProvider::resolve walks the DAG once via first_t_where_graph_registered (envelope-only), then LedgerState::load walks it again (full blobs). For the no-config case (the regressing one) this is fine — probe terminates and we return. For ledgers that DO use fulltext config it's additional latency.

The PR description defers this as item 3, but it's worth at least returning the discovered t from Found(t) so a future commit can use it as a stop_at_t hint or to seed a partial walk. Right now t is logged and discarded.

Forward-positioning comment per PR #1211 review feedback.

Reviewer (@bplatz, approval comment) noted that on chains where the
config graph IS registered, `ApiFulltextConfigProvider::resolve` walks
the DAG once via `first_t_where_graph_registered` (envelope-only,
fast) and then `LedgerState::load` walks it again via
`trace_commits_by_id` (full blobs, slow). The `t` value returned from
`Found(t)` is currently logged and discarded; threading it through to
`LedgerState::load` as a `stop_at_t` hint, or routing config
resolution behind a `g_id`-filtered novelty load, would eliminate
the redundant pass.

The actual optimization requires API design on `LedgerState` (a new
entry point or added parameter) that doesn't fit on this PR. The
`GraphRegistrationProbe::Found(t)` enum already surfaces the value
publicly so a follow-up can pick it up; the only thing missing was
making the future-use intent visible at the consuming match arm.

This commit adds a single block comment at the `Found(t)` arm in
`indexer_fulltext_provider.rs` describing the optimization shape and
referencing the review note. No code change. No test change.

## Verification

- `cargo check -p fluree-db-api` clean.
- `cargo fmt --all -- --check` clean.

## Effect on no-config (regressing) path

None — the `NotFound` arm is unchanged and continues to short-circuit
without `LedgerState::load`. This commit only documents the
follow-up opportunity for the registered-config path.
@aaj3f
aaj3f merged commit 7c71297 into main May 4, 2026
13 checks passed
@aaj3f
aaj3f deleted the fix/reindex-pre-build-perf-regression branch May 4, 2026 19:03
@aaj3f

aaj3f commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

When the config graph IS registered, ApiFulltextConfigProvider::resolve walks the DAG once via first_t_where_graph_registered (envelope-only), then LedgerState::load walks it again (full blobs). For the no-config case (the regressing one) this is fine — probe terminates and we return. For ledgers that DO use fulltext config it's additional latency.

The PR description defers this as item 3, but it's worth at least returning the discovered t from Found(t) so a future commit can use it as a stop_at_t hint or to seed a partial walk. Right now t is logged and discarded.

Added a comment in the code and made a GH issue at #1218

@bplatz bplatz mentioned this pull request May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants