Skip to content

Commit c3ca7e3

Browse files
petehuntPete Hunt
andauthored
Release the GIL when building indexes (#526)
Co-authored-by: Pete Hunt <[email protected]>
1 parent 9b64e41 commit c3ca7e3

File tree

9 files changed

+258
-205
lines changed

9 files changed

+258
-205
lines changed

Cargo.lock

Lines changed: 16 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ name = "tantivy"
1111
crate-type = ["cdylib"]
1212

1313
[build-dependencies]
14-
pyo3-build-config = "0.25.1"
14+
pyo3-build-config = "0.26.0"
1515

1616
[dependencies]
1717
base64 = "0.22"
1818
chrono = "0.4.41"
1919
tantivy = "0.24.2"
2020
itertools = "0.14.0"
2121
futures = "0.3.31"
22-
pythonize = "0.24.0"
22+
pythonize = "0.26.0"
2323
serde = "1.0"
2424
serde_json = "1.0.143"
2525

2626
[dependencies.pyo3]
27-
version = "0.24.2"
27+
version = "0.26.0"
2828
features = ["chrono", "extension-module"]

src/document.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,15 @@ fn extract_value_single_or_list_for_type(
206206
}
207207
}
208208

209-
fn object_to_py(py: Python, obj: &[(String, Value)]) -> PyResult<PyObject> {
209+
fn object_to_py(py: Python, obj: &[(String, Value)]) -> PyResult<Py<PyAny>> {
210210
let dict = PyDict::new(py);
211211
for (k, v) in obj.iter() {
212212
dict.set_item(k, value_to_py(py, v)?)?;
213213
}
214214
Ok(dict.into())
215215
}
216216

217-
fn value_to_py(py: Python, value: &Value) -> PyResult<PyObject> {
217+
fn value_to_py(py: Python, value: &Value) -> PyResult<Py<PyAny>> {
218218
Ok(match value {
219219
Value::Null => py.None(),
220220
Value::Str(text) => text.into_py_any(py)?,
@@ -657,10 +657,10 @@ impl Document {
657657
///
658658
/// For this reason, the dictionary, will associate
659659
/// a list of value for every field.
660-
fn to_dict(&self, py: Python) -> PyResult<PyObject> {
660+
fn to_dict(&self, py: Python) -> PyResult<Py<PyAny>> {
661661
let dict = PyDict::new(py);
662662
for (key, values) in &self.field_values {
663-
let values_py: Vec<PyObject> = values
663+
let values_py: Vec<Py<PyAny>> = values
664664
.iter()
665665
.map(|v| value_to_py(py, v))
666666
.collect::<PyResult<_>>()?;
@@ -824,7 +824,7 @@ impl Document {
824824
&self,
825825
py: Python,
826826
fieldname: &str,
827-
) -> PyResult<Option<PyObject>> {
827+
) -> PyResult<Option<Py<PyAny>>> {
828828
if let Some(value) = self.iter_values_for_field(fieldname).next() {
829829
let py_value = value_to_py(py, value)?;
830830
Ok(Some(py_value))
@@ -840,14 +840,18 @@ impl Document {
840840
///
841841
/// Returns a list of values.
842842
/// The type of the value depends on the field.
843-
fn get_all(&self, py: Python, field_name: &str) -> PyResult<Vec<PyObject>> {
843+
fn get_all(
844+
&self,
845+
py: Python,
846+
field_name: &str,
847+
) -> PyResult<Vec<Py<PyAny>>> {
844848
self.iter_values_for_field(field_name)
845849
.map(|value| value_to_py(py, value))
846850
.collect::<PyResult<Vec<_>>>()
847851
}
848852

849-
fn __getitem__(&self, field_name: &str) -> PyResult<Vec<PyObject>> {
850-
Python::with_gil(|py| -> PyResult<Vec<PyObject>> {
853+
fn __getitem__(&self, field_name: &str) -> PyResult<Vec<Py<PyAny>>> {
854+
Python::attach(|py| -> PyResult<Vec<Py<PyAny>>> {
851855
self.get_all(py, field_name)
852856
})
853857
}
@@ -869,7 +873,7 @@ impl Document {
869873
other: &Self,
870874
op: CompareOp,
871875
py: Python<'_>,
872-
) -> PyResult<PyObject> {
876+
) -> PyResult<Py<PyAny>> {
873877
match op {
874878
CompareOp::Eq => (self == other).into_py_any(py),
875879
CompareOp::Ne => (self != other).into_py_any(py),

src/facet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl Facet {
8888
other: &Self,
8989
op: CompareOp,
9090
py: Python<'_>,
91-
) -> PyResult<PyObject> {
91+
) -> PyResult<Py<PyAny>> {
9292
match op {
9393
CompareOp::Eq => (self == other).into_py_any(py),
9494
CompareOp::Ne => (self != other).into_py_any(py),

0 commit comments

Comments
 (0)