perf(compaction): skip building row-address maps when index remapping is not needed
What changed
- Skip capturing row addresses in compaction workers when the dataset has no remappable data index.
- This avoids scanning the
_rowidcolumn, building an O(number of rewritten rows)RoaringTreemap, and serializing/transferring it to the commit process. - Deferred index remapping still captures row addresses because the fragment-reuse index (FRI) consumes them.
- This avoids scanning the
- Make
IndexRemapperOptions::create_remapperasync and returnResult<Option<Box<dyn IndexRemapper>>>. - Return
Nonewhen the dataset has no remappable index metadata, including datasets with only FRI or other system indices. - Create the remapper before materializing the potentially large old-to-new row-address
HashMapduring commit. - Reuse the index metadata snapshot loaded during remapper creation, while excluding system indices from actual remapping.
- Add regression coverage for:
- datasets with no indices;
- datasets with only system/FRI metadata;
- datasets with a normal data index;
- commit-time skipping when no remapper exists;
- deferred versus immediate remapping under equivalent indexed conditions.
Why
For datasets without stable row IDs, compaction could previously perform two layers of work before discovering that no index could consume the result:
- Workers captured every old row address into a
RoaringTreemapand serialized it. - The commit process expanded those addresses into an old-to-new
HashMap.
Both structures scale with the number of rewritten rows and are unnecessary when no data index needs remapping. On large distributed compactions, either layer can create avoidable memory pressure or OOM.
This PR skips the work at the earliest safe point and retains the commit-side guard for completed tasks that already contain row addresses.
Compatibility note
IndexRemapperOptions is a public trait. This intentionally changes create_remapper from:
fn create_remapper(&self, dataset: &Dataset) -> Result<Box<dyn IndexRemapper>>;
to:
async fn create_remapper(
&self,
dataset: &Dataset,
) -> Result<Option<Box<dyn IndexRemapper>>>;
This is a source-breaking API change for external trait implementors and direct callers: implementations must become async, callers must await the result, and both must handle Option. This trade-off has been discussed with a project collaborator.
Related work and attribution
This incorporates the worker-side optimization from #7773 after coordination with its author. Yue Zhang's contribution is preserved in commit with:
Co-authored-by: Yue Zhang <[email protected]>
Thanks @zhangyue19921010 for the original implementation and collaboration.
Validation
cargo fmt --all -- --checkcargo test -p lance dataset::index::tests::test_remapper_not_created_without_remappable_indices --lib -- --exactcargo test -p lance dataset::optimize::tests::test_row_addrs_only_used_with_remappable_index --libcargo test -p lance dataset::optimize::tests::test_defer_index_remap --lib -- --exact
[!NOTE]
Reviews paused
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
- [ ] ▶️ Resume reviews
- [ ] 🔍 Trigger review
📝 Walkthrough
Walkthrough
Makes index remapper creation asynchronous and optional, caches index metadata, and gates compaction row-address capture and index rewriting on the presence of remappable indices.
Changes
Index remap gating
| Layer / File(s) | Summary |
|---|---|
Remapper contract rust/lance/src/dataset/optimize/remapping.rs, rust/lance/src/dataset/optimize.rs |
create_remapper now asynchronously returns an optional remapper; implementations return either Some or None. |
Dataset index metadata loading rust/lance/src/dataset/index.rs |
System indices are excluded from remapping, metadata is loaded asynchronously and cached, and tests cover absent and required remappers. |
Compaction remap flow rust/lance/src/dataset/optimize.rs |
Compaction conditionally captures row addresses and rewrites indices based on remapper availability, with coverage for non-remappable datasets. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Sequence Diagram(s)
sequenceDiagram
participant commit_compaction
participant DatasetIndexRemapperOptions
participant DatasetIndexRemapper
participant RewriteResult
commit_compaction->>DatasetIndexRemapperOptions: create_remapper().await
DatasetIndexRemapperOptions->>DatasetIndexRemapper: preload index metadata
DatasetIndexRemapper-->>commit_compaction: Some(remapper) or None
commit_compaction->>DatasetIndexRemapper: remap_indices() when Some
DatasetIndexRemapper-->>RewriteResult: rewritten indices
Possibly related PRs
- lance-format/lance#7549: Also changes the dataset index remapping implementation.
- lance-format/lance#7773: Also changes compaction conditions around index remapping and row-address output.
- lance-format/lance#7774: Also changes fragment-reuse handling around deferred index remapping.
Suggested labels: bug, performance
Suggested reviewers: wjones127, jackye1995, westonpace
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| 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 matches the main change: compaction now skips row-address map building when index remapping is unnecessary. |
✨ Finishing Touches
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
Comment @coderabbitai help to get the list of available commands.
Codecov Report
:x: Patch coverage is 89.70588% with 7 lines in your changes missing coverage. Please review.
:loudspeaker: Thoughts on this report? Let us know!