mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
perf(python): add direct sync query execution (#5141)
## Summary Route ordinary local `table.search(...).to_arrow()` queries through private synchronous schema and eager-collection bindings instead of the Python background event loop. Plain scans, vector searches (including default vector-column inference), and native FTS in lazy Blob mode now complete with zero `LOOP.run` submissions. The synchronous path reuses the existing query lowering, core query execution, eager collector, Arrow ownership, projection validation, fragments, row ids, Blob finalization, reranking, and snapshot handling. It uses the generation-scoped Tokio runtime and `OutstandingGuard`, releases the GIL while waiting, checks CPython signals on the caller thread at a bounded interval, and aborts and drops collected state when a handler raises. Multi-threaded Tokio callback re-entry uses `block_in_place`; current-thread contexts return a Python error. Namespace, RemoteTable, Enterprise, streaming, take, and non-lazy Blob routing are unchanged. No public API is added. ## Benchmark Workload: 200,000 rows, 64 dimensions, BTREE on `id`, IVF_PQ on `vector`; 50 warmups + 500 calls, p50/p99 of three alternating runs. Build: `release-with-debug`. Baseline Python package from `03fc5404` ran against the same candidate extension as the candidate, so this isolates the Python event-loop route; a separately built matching baseline extension is a follow-up validation target. The host had competing Rust builds, so these numbers are preliminary, not isolated release throughput. | Workload | LOOP/schema per call before -> after | p50 before -> after | p99 before -> after | |---|---|---|---| | plain point lookup `to_arrow()` | 2 / 1 -> 0 / 1 | 2.32 / 3.26 / 2.64 ms -> 1.64 / 1.89 / 1.80 ms | 3.87 / 3.92 / 3.69 ms -> 2.42 / 2.63 / 2.62 ms | | indexed vector `to_arrow()` | 3 / 2 -> 0 / 2 | 5.20 / 5.13 / 3.79 ms -> 4.65 / 4.22 / 4.31 ms | 7.18 / 7.52 / 6.45 ms -> 6.29 / 6.01 / 6.43 ms | `to_batches()` remains on the existing streaming path. OSS-2868 1/2/4/8/16-thread scaling and fully matched build artifacts remain separate follow-up. ## Validation - `test_sync_query_direct.py`: plain/vector/native FTS with `LOOP.run` patched to fail, default vector inference, empty schema, timeout, single-worker progress-callback re-entry, and SIGINT/runtime reuse. - `test_query.py` with direct tests: 253 passed, 1 skipped. - `test_blob.py`: 266 passed, 1 skipped. - `test_fts.py` + `test_rerankers.py`: 163 passed, 13 skipped. - `test_table.py` + `test_namespace.py` + `test_sync_api_parity.py`: 649 passed, 17 skipped. - Remote query/blob/schema subset: 206 passed. - Runtime unit tests: 12 passed; `cargo check`, `cargo clippy`, `cargo fmt --check`, and Python ruff passed. The SIGINT case is marked slow and was run in focused validation; it is not part of the default suite. Refs OSS-2867 (non-closing).
This commit is contained in:
+9
-1
@@ -9,7 +9,7 @@ use std::{
|
||||
},
|
||||
};
|
||||
|
||||
use crate::runtime::{block_on, future_into_py, spawn_background};
|
||||
use crate::runtime::{block_on, block_on_interruptible, future_into_py, spawn_background};
|
||||
use crate::{
|
||||
connection::Connection,
|
||||
error::PythonErrorExt,
|
||||
@@ -1619,6 +1619,14 @@ impl Table {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn schema_sync(self_: PyRef<'_, Self>) -> PyResult<Py<PyAny>> {
|
||||
let inner = self_.inner_ref()?.clone();
|
||||
let schema = self_.py().detach(move || {
|
||||
block_on_interruptible(async move { inner.schema().await.infer_error() })
|
||||
})?;
|
||||
Python::attach(|py| schema.to_pyarrow(py).map(|obj| obj.unbind()))
|
||||
}
|
||||
|
||||
#[pyo3(signature = (data, mode, progress=None, write_parallelism=None, allow_external_blob_outside_bases=false, retries=None))]
|
||||
pub fn add<'a>(
|
||||
self_: PyRef<'a, Self>,
|
||||
|
||||
Reference in New Issue
Block a user