Repository navigation
Conversation
Every `lance.dataset()` opened without a session builds its own `Arc<Manifest>` holding the table's whole fragment list, plus its own index and metadata cache budgets and its own object-store client. Daft opens one per scan task, per writer flush and per maintenance instance, so a many-fragment table pays that again for every concurrently open dataset. Pass one process-level `Session` to every open instead. The manifest is a metadata-cache entry keyed by (uri, version, e_tag), so every open of the snapshot the driver pinned hands back a clone of the same `Arc<Manifest>`. `read_blobs` additionally stops closing over the driver's `LanceDataset`: `__reduce__` ships the whole re-encoded manifest per task, which both inflates the payload and bypasses the session's manifest cache. It now carries the uri plus the pinned open kwargs and reopens once per worker process. `DAFT_LANCE_SHARE_SESSION=0` restores lance's per-open sessions. It is an escape hatch, and the only way to get pre-sharing behavior inside a Ray worker, which is what the A/B benchmark needs: a driver-side monkeypatch never reaches the worker. Measured in a Ray worker on a KubeRay cluster, `read_lance` -> `write_parquet` (a write rather than an aggregation on purpose: a task holds its parquet buffers at the same time as its manifest, so the two compete for one memory limit): - 4000 fragments x 10k rows, concurrency 24, whole table: worker ru_maxrss grew 206.5 MB unshared against 157.4 MB shared, so 49.1 MB less resident. Daft's own sampled peak agrees (487.8 vs 442.1 MB). - 100k fragments x 10k rows, concurrency 8, reading 1% in groups of ten: 1052.2 MB against 573.3 MB, so 479.0 MB less resident -- and the pipeline finished in 61.9s instead of 609.6s. At that scale the cost of not sharing is mostly time: each unshared task re-parsed the same 8 MB manifest, about 5.5s of the 6.1s it spent. - Repeated `nearest` queries on a 200k-row IVF_PQ index run 1.7-2.0x faster, because the index is loaded once per process instead of once per query. The maintenance path is the exception and is covered so the exception stays documented: Daft runs each `daft.cls` instance in a process of its own, so a maintenance worker opens the table exactly once however high the concurrency, and nothing multiplies by it. An indexed table does not change that -- a task's open brings in the index's metadata entry only, and the index data is read once on the driver, when the compaction commit remaps it onto the new fragment ids. Tests assert the mechanism rather than the megabytes: `Session.size_bytes()` is exact, needs no large table, and is zero for any open that did not go through the process session. `benchmarks/lance_session_memory.py` (`make bench`) is the counterpart that puts numbers on it.
4 of 5 tasks
FANNG1
marked this pull request as ready for review
November 12, 2026 23:40
Contributor
Author
|
@rchowell @universalmind303 @ChaosJu could you please review this PR? It shares Lance metadata and index caches through a process-local Session to reduce repeated Dataset-open costs, particularly when small-batch appends repeatedly open a destination with a large manifest. Explicit Sessions and cache-size settings retain independent behavior. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #92
Summary
Repeated dataset opens can repeatedly load and decode the same large Lance manifest. This is particularly expensive when
write_fragmentsopens an existing destination for every small batch. Reads and other operations that open the same table in one process can incur the same cost.Share one
lance.Sessionper process across dataset opens and fragment writes, allowing Lance to reuse its metadata and index caches. Dataset handles remain independently owned; this PR does not introduce a process-wide Dataset cache.Implementation
lance.Session. A small selection helper is shared by the thinopen_dataset(uri, **kwargs)wrapper and maintenance's low-level constructor.None(including zero), no shared Session is injected: Lance interprets the options and creates an independent Session. Calls no longer depend on which table or configuration was opened first.DAFT_LANCE_SHARE_SESSION=0/false/norestores Lance's normal per-open behavior.DAFT_LANCE_INDEX_CACHE_SIZE_BYTESandDAFT_LANCE_METADATA_CACHE_SIZE_BYTESconfigure only the default shared Session; invalid values report the setting and cannot be mistaken for a missing table by the sink.read_blobsuses serializableDatasetOpenContextstate rather than shipping the driver's Dataset/manifest. Each deserialized UDF closure opens once successfully under a lock and reuses that handle across batches. Preserve Lance-exposed read, base-store, storage, and default scan options. Namespace inputs may supply an originatingopen_contextto retain namespace reconstruction and credential refresh. Without it, the existingread_blobs(df, ds, column)call keeps the original Dataset closure behavior rather than failing; this fallback retains Lance's existing serialization limitations. Explicit contexts with mismatched URI/version or missing namespace addressing are rejected.DatasetOpenContextfor pinned worker reopens; no duplicateDatasetOpenOptionsparameter model remains.Cache reuse still depends on Lance's cache keys, loading path, and capacity. This does not eliminate latest-version resolution or add a V1-manifest workaround. A URI must consistently identify the same underlying dataset; identical URIs referring to different endpoint data require isolation.
README documents behavior and configuration. Historical measurements and version-specific process-layout observations live in
docs/session-performance.md, rather than being enforced as functional test contracts.Local append benchmark
These measurements preceded the lifecycle simplification; they were not rerun for this refactor.
Run
read_lance→write_lance(mode="append")on local Ray configured with 4 CPUs, using Daft 0.7.14 and pylance 12.0.0. Each run reads and appends 10,000 rows, with Lance scan batch size 16, into a pre-existing target. Each Session setting starts from a separate target with the same initial fragment count and manifest size.At 100,000 fragments, sharing reduced wall time by approximately 9.2× and CPU time by 89%. CPU utilization remained around one core: the improvement was less time spent doing the work, rather than lower instantaneous utilization.
Measurement boundaries:
Validation
After the lifecycle and selection changes:
Blob compatibility follow-up: native Blob/shared-Session tests passed (46 passed, 1 skipped); Ray Session tests plus both namespace Blob paths passed (9 passed). Added committed regressions for direct Lance namespace inputs without a Daft-Lance handle, optional serialized namespace context, URI/version/namespace mismatch, read/base-store parameters reaching the real Dataset constructor, and one open per deserialized UDF instance under concurrent calls. The base-store test checks forwarding, not remote authentication.
The benchmark scripts remain local-only; no performance benchmark was added to IT.