Skip to content

perf(index): pack prewarmed FTS posting groups#7720

Merged
BubbleCal merged 5 commits into
mainfrom
yang/fts-runtime-posting-groups
Jul 10, 2026
Merged

perf(index): pack prewarmed FTS posting groups#7720
BubbleCal merged 5 commits into
mainfrom
yang/fts-runtime-posting-groups

Conversation

@BubbleCal

@BubbleCal BubbleCal commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Performance issue

No-position FTS prewarm currently decodes posting rows into a Vec<PostingList> object graph. This substantially amplifies the index cache for workloads dominated by singleton and small posting lists.

Measured before this change:

  • 10M globally unique terms: 2.76 GB cache for a 239.6 MB index (11.53x)

How this improves performance

This PR:

  • replaces index-time posting-group metadata with runtime synthetic groups, so existing indexes benefit without rebuilding;
  • stores no-position prewarmed groups as compact Arrow-backed posting rows instead of materializing every posting list;
  • creates a lightweight posting-list view only for the term used by a query, sharing the cached posting buffers;
  • keeps score and length metadata in the posting reader for prewarmed groups;
  • retains the materialized fallback for legacy and position-bearing paths;
  • versions the cache codec while continuing to read the previous materialized group representation.

The persistent FTS index format and public API do not change. prewarm_index still populates the posting cache for subsequent queries.

Benchmark

Fresh c4-standard-16 VM, no-position format-v2 indexes created once by baseline Lance 5dbd1400d, then reused unchanged by the target. The target uses the default runtime group size of 128. Each prewarm result is the mean of five runs.

Dataset Main cache Target cache Change Cold prewarm
10M unique terms 2.762 GB 250.3 MB -90.94% 6.440s -> 0.895s
Wikipedia-40M 8.423 GB 3.724 GB -55.79% 15.697s -> 6.860s

A 64/128/256 sweep selected 128: compared with 256 it halves cache-group granularity for a 2.36% cache increase on 10M unique terms and 0.29% on Wikipedia-40M. Size 64 increased the 10M cache by 7.07% and cold prewarm time by 30.8%.

Three repeated, prewarmed query runs at group size 128 showed no materialization regression. Mean QPS changed by -0.7% to +0.6% across the 10M unique-term and Wikipedia k=10/k=100 workloads, within run-to-run variance.

Validation

  • cargo fmt --all -- --check
  • cargo test -p lance-index scalar::inverted --lib --profile release-with-debug (197 passed)
  • cargo clippy --all --tests --benches -- -D warnings
  • same-index benchmark validation: every query run reported index_action=reused and prewarm_with_position=false

Addresses OSS-1409.

Summary by CodeRabbit

  • New Features
    • Added runtime synthetic posting-list grouping for non-legacy v2 indexes.
    • Introduced a more compact packed posting-list cache format and packed-group prewarming.
  • Bug Fixes
    • Preserved backward-compatible decoding by falling back to the legacy layout.
    • Added consistency validation for packed cache contents and ensured BM25 correctness.
  • Refactor
    • Removed persisted posting-group boundary bookkeeping; grouping is now computed at runtime.
  • Tests
    • Updated and extended tests for packed vs materialized groups, including roundtrip and zero-copy coverage.

@github-actions github-actions Bot added the A-index Vector index, linalg, tokenizer label Jul 10, 2026
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The inverted index removes persisted posting-group boundaries, adds runtime token-count grouping, and introduces packed posting-list group storage with versioned cache serialization and legacy decoding support. Reader, prewarm, writer, memory-accounting, and end-to-end tests are updated accordingly.

Changes

Synthetic posting groups

Layer / File(s) Summary
Remove persisted group boundaries
rust/lance-index/src/scalar/inverted/builder.rs, rust/lance-index/src/scalar/inverted/encoding.rs, rust/lance-index/src/scalar/inverted/index.rs
Posting-list writing no longer accumulates or persists group-start metadata, and the related encoding helpers, configuration, and tests are removed.
Packed group storage and cache format
rust/lance-index/src/scalar/inverted/index.rs, rust/lance-index/src/scalar/inverted/cache_codec.rs
Posting-list groups now support packed and materialized storage; cache format version 2 serializes packed IPC batches with compact codec tags and retains version 1 materialized decoding.
Runtime grouping for reads and prewarm
rust/lance-index/src/scalar/inverted/index.rs
Runtime token-count grouping drives reader ranges, packed group loading, prewarm chunk alignment, cache publication, metadata handling, memory accounting, and regression tests.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Query
  participant PostingListReader
  participant PostingGrouping
  participant PostingListGroup
  Query->>PostingListReader: request token postings
  PostingListReader->>PostingGrouping: calculate synthetic group range
  PostingGrouping-->>PostingListReader: return group range
  PostingListReader->>PostingListGroup: load packed group
  PostingListGroup-->>PostingListReader: return posting view
  PostingListReader-->>Query: return postings
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main performance change: packing prewarmed FTS posting groups.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch yang/fts-runtime-posting-groups

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.85502% with 98 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance-index/src/scalar/inverted/index.rs 85.77% 47 Missing and 20 partials ⚠️
...ust/lance-index/src/scalar/inverted/cache_codec.rs 77.03% 18 Missing and 13 partials ⚠️

📢 Thoughts on this report? Let us know!

@BubbleCal BubbleCal marked this pull request as ready for review July 10, 2026 04:05

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

Claude Code Review is paused for this repository. To reconnect it, an admin of this repository's GitHub organization (or the account owner, for personal repositories) who can also manage your Claude organization's Code Review settings needs to re-link GitHub in Code Review settings. This is a one-time step.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@rust/lance-index/src/scalar/inverted/index.rs`:
- Around line 1259-1263: Document the PostingGrouping enum variants with concise
behavioral semantics: describe None as ungrouped legacy or empty partitions, and
SyntheticFixed as using a fixed cache group size; clarify that group_size is
measured in token rows, not posting bytes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: bd5a9f7d-4465-49e3-ba68-272221a1e4aa

📥 Commits

Reviewing files that changed from the base of the PR and between 5ba1e20 and f60976e.

📒 Files selected for processing (4)
  • rust/lance-index/src/scalar/inverted/builder.rs
  • rust/lance-index/src/scalar/inverted/cache_codec.rs
  • rust/lance-index/src/scalar/inverted/encoding.rs
  • rust/lance-index/src/scalar/inverted/index.rs
💤 Files with no reviewable changes (1)
  • rust/lance-index/src/scalar/inverted/encoding.rs

Comment thread rust/lance-index/src/scalar/inverted/index.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
rust/lance-index/src/scalar/inverted/index.rs (1)

3703-3843: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optional: de-duplicate the POSTING_COL List<LargeBinary> extraction.

The exact column_by_name(POSTING_COL) → as_list_opt::<i32>() → ok_or_else(...) block (with an identical error message) is repeated in new_packed (Lines 3707-3714) and posting_list (Lines 3803-3811). A small private helper on PackedPostingListGroup would keep the error text and cast in sync if either changes later.

♻️ Example helper extraction
impl PackedPostingListGroup {
    fn postings_column(&self) -> Result<&GenericListArray<i32>> {
        self.batch
            .column_by_name(POSTING_COL)
            .and_then(|column| column.as_list_opt::<i32>())
            .ok_or_else(|| {
                Error::index(format!(
                    "packed posting group column {POSTING_COL} must be List<LargeBinary>"
                ))
            })
    }
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rust/lance-index/src/scalar/inverted/index.rs` around lines 3703 - 3843,
Deduplicate the repeated POSTING_COL List<LargeBinary> extraction by adding a
private postings_column helper on PackedPostingListGroup that performs the
existing lookup, cast, and error construction. Update new_packed and
posting_list to use this helper while preserving their current validation and
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@rust/lance-index/src/scalar/inverted/index.rs`:
- Around line 3703-3843: Deduplicate the repeated POSTING_COL List<LargeBinary>
extraction by adding a private postings_column helper on PackedPostingListGroup
that performs the existing lookup, cast, and error construction. Update
new_packed and posting_list to use this helper while preserving their current
validation and behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0537d44b-95e2-4380-9ae0-b595a9136c8e

📥 Commits

Reviewing files that changed from the base of the PR and between f60976e and baa023e.

📒 Files selected for processing (1)
  • rust/lance-index/src/scalar/inverted/index.rs

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice change!

@BubbleCal BubbleCal merged commit 5cb1569 into main Jul 10, 2026
48 of 49 checks passed
@BubbleCal BubbleCal deleted the yang/fts-runtime-posting-groups branch July 10, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-index Vector index, linalg, tokenizer performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants