Skip to content

test(cleanup): verify managed subtree listings overlap - #11167

Merged
Xuanwo merged 2 commits into
lance-format:mainfrom
lichuang:perf-cleanup-listing
Dec 2, 2026
Merged

Xuanwo merged 2 commits into
lance-format:mainfrom
lichuang:perf-cleanup-listing

Conversation

@lichuang

@lichuang lichuang commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

The concurrent listing implementation and latency benchmark landed in #11596. This PR retains the regression test from the original contribution. It calls cleanup().explain() and checks that the data/ and _transactions/ listings both await their first response at the same time. With serial listing, the same test fails at the overlap assertion.

Original implementation and measurements before #11596 landed

Summary

Cleanup listed its managed directories through a serial flatten(), so a large
data/ listing delayed _indices/, _deletions/, _blobs/,
_transactions/, _versions/, and _fri/ even though they are independent.
Each subtree is a single paginated LIST, so those round trips were paid one
after another.

This PR overlaps them with flatten_unordered, and builds each subtree stream
directly from read_dir_all instead of wrapping every listed object in its own
boxed stream.

About the numbers in the previous revision

The earlier description was measured on my MacBook Pro. That machine is not a
controlled environment — desktop session, uneven thermal throttling, varying
background load — and its run-to-run spread was on the order of the effect
being claimed. That is very likely why serial flatten() after de-boxing
looked ~10% slower than before, which should be impossible from removing an
allocation.

Everything below has been re-measured on a clean Linux machine (32 cores,
59 GB, no desktop session, nothing else running) with the variants interleaved
so drift and page-cache state hit all of them equally. The absolute times are
much lower here because the machine is faster, not because the code changed.

Only differences within a single machine are meaningful, so the old and new
tables are not comparable with each other and should not be mixed.

Corrected claim about allocations

The previous description credited the per-object de-boxing with a speed-up.
That does not hold up, and the review was right to question it:

  • De-boxing removes about one allocation per listed object, but
    flatten_unordered re-inserts its next-item future into its scheduler after
    every emitted item, adding roughly the same number back. Over 700k items the
    allocation count is 700,007 both before and after.
  • Measured on its own, de-boxing while keeping the serial merge is
    indistinguishable from the previous code.

The de-boxing is kept because it is a simplification that disappears in the
noise, not because it pays. The gain in this PR is entirely from overlapping
the listings.

Benchmark

Same harness as #10511, one machine, variants interleaved (A/B/C adjacent).

  • release-with-debug, sample size 20, warm-up 5s, measurement 15s
  • local file-object-store
  • CLEANUP_BENCH_ORPHANS=2000, CLEANUP_BENCH_VERSIONS=200
  • medians of 3 interleaved rounds
Variant orphans/2000 versions/200
before (serial flatten) 17.15 ms 12.65 ms
de-boxed, still serial 17.20 ms 12.66 ms
this PR 10.77 ms 5.60 ms
−37% −56%

The de-boxed row is the point the review raised: removing the per-object stream
buys nothing measurable on its own, so the entire change is the concurrency.

Modeling object-store listing latency

A local filesystem has no LIST round trip, so the local numbers understate what
this change is for. The benchmark now accepts
CLEANUP_BENCH_LIST_LATENCY_MICROS, which charges every LIST a fixed delay
inside the timed region only (setup stays unthrottled). With 1000 µs, roughly a
same-region object store:

Variant orphans/2000 versions/200
before (serial flatten) 27.40 ms 21.63 ms
de-boxed, still serial 26.35 ms 21.71 ms
this PR 14.70 ms 8.64 ms
−46% −60%

This is still a modeled delay, not a real remote store. It shows the shape of
the win rather than its absolute size on S3 or GCS.

What is unchanged

  • Which files cleanup selects and deletes.
  • The listing cutoffs, including the _versions/_indices rules that scan
    without a retained-manifest cutoff.
  • Delete request counts: 2000 requests for 2000 paths in the orphan scenario
    and 597 for 597 paths in the version scenario, before and after.

The outer composition (unreferenced files, then local staging files, then
manifests) is also unchanged.

Tests

  • New rust/lance/src/dataset/cleanup/tests/listing.rs: a store wrapper holds
    each listing open and records the peak number of in-flight listings. The test
    asserts more than one managed subtree is in flight at a time, and fails on a
    serial merge. It asserts overlap, not duration, so it does not depend on
    machine speed.
  • cargo test -p lance --lib dataset::cleanup: 311 passed.
  • cargo clippy -p lance --all-targets -- -D warnings: clean.
  • cargo fmt --all: clean.

The full workspace test suite was not run; the change is confined to cleanup
listing and the cleanup benchmark.

Review follow-ups in this revision

These three are folded into the PR and do not change performance — the numbers
above already describe the original commit:

  • Dropped the comment describing the removed per-object boxing, and moved the
    history of the previous flatten() into the commit message.
  • Corrected the concurrency note: read_dir_all is a single paginated LIST, so
    the merge is at most one in-flight LIST per subtree — not something bounded
    by the store's own listing concurrency. None is used instead of restating
    streams.len().
  • Added the concurrency regression test and the modeled LIST latency to the
    benchmark.

Notes

  • No file-format or API changes.
  • flatten_unordered costs roughly 83–108 ns per item in scheduler overhead
    when measured with no I/O. At cleanup's real scale (~600 files in the version
    scenario, 2000 in the orphan scenario) that is not observable end to end, but
    a zero-allocation merge is a reasonable later optimisation if it ever is. It
    was measured at parity here, so it is not part of this PR.
    hint: if you need to wait for this pull request to be reviewed, merged, or closed before continuing, use this instead of polling:
    gh event listen --resource test(cleanup): verify managed subtree listings overlap #11167 --event com.github.pull_request.review.submitted.v1,com.github.pull_request.state.changed.v1
    • It prints the first event as a JSON line on stdout and exits; run it again to wait for the next one.
    • Add --timeout to stop waiting after a while, for example --timeout 30m; it then exits with status 8.
    • Events carry no details; read the pull request to see what changed.
    • It misses changes made before it starts, so read the pull request once it is running.
    • See gh event listen --help for other event types.
    • Event subscriptions are in preview and may not be enabled for your account.

@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

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. and removed K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 17, 2026

@lance-gatekeeper lance-gatekeeper Bot 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.

⚠️ Gate recommendation: approve with a non-blocking risk.

The author accepts the per-candidate allocation and CPU scheduling overhead to retain overlapping subtree listings. That performance trade-off remains non-blocking; no further change is requested for this finding.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 17, 2026

@wjones127 wjones127 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.

Thanks, this is a nice small change. Listing the managed subtrees concurrently makes sense, and the NotFound handling and the outer ordering (unreferenced files, then staging files, then manifests) are unchanged. Nothing here blocks.

Non-blocking: a question about whether the benchmark shows a real win given run-to-run noise, plus two comment nits.

question: How noisy is this benchmark run to run? In your reply table, serial flatten after de-boxing comes in at 103.9–105.7 ms vs 94.4 ms on main for orphans, and 32.7–33.9 ms vs 31.3 ms for versions. Removing an allocation per object shouldn't make things ~10% slower, so I suspect the variance between runs is about as big as the 8% improvement. Also, per the gatekeeper's probe, flatten_unordered adds back about one allocation per item, so the de-boxing win mostly cancels out.

The concurrency should really pay off on object stores, where each LIST page has real latency. Could we measure that directly, for example by running main and this branch interleaved, or by using a local store with injected list latency? I'm fine merging either way since this is easy to revisit. I'd just like the PR description to make a claim the numbers support.

Comment thread rust/lance/src/dataset/cleanup.rs Outdated
// `flatten()` consumed one directory stream at a time, so a large
// `data/` directory delayed listing of `_indices/`, `_deletions/`,
// etc. Each stream is already bounded by the object store's own
// listing concurrency.

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.

nitpick: "Each stream is already bounded by the object store's own listing concurrency" isn't quite right. read_dir_all is a single paginated list(), so each subtree is one sequential LIST, and total concurrency is just the number of subtrees. Also, the history ("The previous flatten()...") fits better in the commit message. Since all the streams are already in hand, None gives the same behavior as Some(streams.len()). Maybe:

        // List the managed subtrees concurrently so a large `data/` listing
        // doesn't delay `_indices/`, `_deletions/`, etc. Each subtree is a
        // single paginated LIST, so this is at most one in-flight LIST per subtree.
        let unreferenced_files = stream::iter(streams).flatten_unordered(None).boxed();

Comment thread rust/lance/src/dataset/cleanup.rs Outdated

// Build stream for a managed subtree
// Build stream for a managed subtree. Keep the object metadata stream
// unboxed: the previous per-object `stream::once(...).boxed()` created

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.

nitpick: This describes code that no longer exists, which won't mean much to a future reader. I'd drop it and keep just // Build stream for a managed subtree.. The NotFound comment below already explains the part that isn't obvious.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks — the benchmark question was fair, and it changed the conclusion I should have drawn from my own numbers. The description is updated.

The old numbers came from my MacBook Pro, which is not a controlled environment: desktop session, uneven thermal throttling, varying background load. Its run-to-run spread was on the order of the effect I was claiming, which is very likely why serial flatten() after de-boxing looked ~10% slower than before — impossible from removing an allocation.

I re-ran everything on a relatively clean Linux box (32 cores, 59 GB, no desktop session, nothing else running), with the variants interleaved so drift and page-cache state hit all of them equally. Medians of 3 rounds, release-with-debug, 20 samples, 5s warm-up / 15s measurement, 2000 orphans / 200 versions.

The absolute times are much lower than the old table because the machine is faster, not because the code changed. The two tables are not comparable; only within-machine differences mean anything.

You were right about the de-boxing

Variant orphans/2000 versions/200
before (serial flatten) 17.15 ms 12.65 ms
de-boxed, still serial 17.20 ms 12.66 ms
this PR 10.77 ms 5.60 ms
−37% −56%

De-boxing saves ~one allocation per listed object, but flatten_unordered re-inserts its next-item future after every item and adds them back — over 700k items it is 700,007 both before and after, exactly the cancellation you predicted. On its own it moves nothing. I keep it as a simplification, not for speed; the description no longer credits it with the win.

Measuring the case this change is for

You're right that local file-object-store has no LIST round trip. I added CLEANUP_BENCH_LIST_LATENCY_MICROS, which charges each LIST a fixed delay inside the timed region only (setup stays unthrottled). At 1000 µs:

Variant orphans/2000 versions/200
before (serial flatten) 27.40 ms 21.63 ms
this PR 14.70 ms 8.64 ms
−46% −60%

A modeled delay, not a real remote store: it shows the shape of the win, not its size on S3. Delete request counts are unchanged (2000/2000 and 597/597).

Cleanup listed each managed directory through a serial `flatten()` over
directory streams. A large `data/` directory therefore delayed listing of
`_indices/`, `_deletions/`, and the other independent subtrees.

The listing path also wrapped every object metadata item in a boxed
`stream::once(...)` and immediately flattened it, allocating one boxed stream
per listed object.

Build directory streams directly from `read_dir_all` with `filter_map` and
`try_filter_map`, treating a missing managed directory as an empty subtree.
Then consume the independent directory streams with `flatten_unordered` so they
are listed concurrently.

Benchmark with `release-with-debug`, 20 samples, 2000 orphans and 200 versions:

- `cleanup/orphans/2000`: 94.398 ms -> 95.837 ms (+1.5%, p=0.91, no change)
- `cleanup/versions/200`: 31.339 ms -> 28.817 ms (-8.0%, p<0.05)

Delete request counts are unchanged: 2000 for the orphan scenario and 597 for
the version scenario. The version scenario benefits because cleanup scans
multiple managed subtrees; the orphan scenario is dominated by the 2000
deletes.

`cargo test -p lance cleanup::tests`: 231 passed.
@lichuang
lichuang force-pushed the perf-cleanup-listing branch from dd3f2d0 to 891cc9b Compare November 18, 2026 05:22
@lance-gatekeeper lance-gatekeeper Bot removed K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 18, 2026
Merge main to use the cleanup implementation and benchmark from lance-format#11596. Keep the overlap regression from lance-format#11167, observing only the data and transaction listings in the sweep.

Co-authored-by: codedump <[email protected]>
@Xuanwo Xuanwo changed the title perf(cleanup): parallelize managed subtree listings test(cleanup): verify managed subtree listings overlap Dec 2, 2026
@github-actions github-actions Bot added the chore label Dec 2, 2026
@Xuanwo
Xuanwo merged commit 17622c5 into lance-format:main Dec 2, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants