HyukjinKwon opened a new pull request, #579: URL: https://github.com/apache/spark-connect-rust/pull/579
### What changes were proposed in this pull request? This PR upgrades PyO3 from 0.28.3 to 0.29.3 and Arrow from 58.3.0 to 59.3.2. arrow-pyarrow 59 is the first release line on PyO3 0.29, so the two move together. The optional `datafusion` feature moves from DataFusion 53 to 55.2.0, the release on Arrow 59; no DataFusion release is on Arrow 60 yet. It removes `crates/pyspark-rs/src/instance_dict.rs`, the `tp_dealloc` wrapper of SPARK-61490 that released the instance `__dict__` of the `#[pyclass(dict)]` classes. PyO3 0.29 does this itself: it releases the dict at dealloc (`release_dict`), keeps the dict that `object.__new__` makes on CPython 3.11 and 3.12, and synthesizes `tp_traverse`/`tp_clear` for dict classes, so the garbage collector sees the dict. AGENTS.md, `docs/installation.md` and the comments that cited PyO3 0.28 or Arrow 58 are updated. No API adaptation was needed. ### Why are the changes needed? With PyO3 0.28, every instance of the Python client's dict classes (Column, DataFrame, SparkSession, the data types, readers, writers, Observation and others) leaked the empty dict that CPython 3.11 and 3.12 create for it, about 64 bytes. And because PyO3 0.28 GC-tracks a class only if it defines `__traverse__`, a reference cycle through an instance dict was never collected, while PySpark's plain classes collect it: ```python import gc, weakref df = spark.range(1) df.me = df ref = weakref.ref(df) del df gc.collect() ref() # PySpark: None. Before: the DataFrame is still alive. After: None. ``` Measured on CPython 3.11, 20,000 instances given no attribute kept 1,289,830 bytes before this change. ### Does this PR introduce _any_ user-facing change? Yes: these leaks and uncollected cycles are gone. There is no API change. The `datafusion` feature now needs Rust 1.94, which `docs/installation.md` notes; the published crates keep their Rust 1.88 minimum. ### How was this patch tested? - New `test_cycles_through_instance_dicts_are_collected_as_pyspark`: a cycle through the instance dict of a DataFrame, a Column, an Observation, a reader and the conf is collected. - `test_freed_instances_given_attributes_keep_no_memory_as_pyspark` now also asserts that 20,000 instances given no attribute keep under 20,000 bytes. Its old baseline subtraction hid the leak. - Both fail with PyO3 0.28 (rebuilt and run on CPython 3.11) and pass with 0.29. - Offline suites (`test_dropin_offline.py`, `test_arrow_handoff.py`, `test_ml_offline.py`, `TZ=UTC`) on CPython 3.11, 3.12 and 3.13: 3262 passed and 8 skipped on each. - Python e2e suites against Spark 4.3.0 on 3.11: 358 passed, 1 skipped. - Rust: the lib tests of apache-spark-connect and apache-spark-connect-core, the lib tests with `datafusion,polars`, the `--no-run` builds of the default, `wasm-udf` and `datafusion,polars` targets, and the Rust e2e suites. One e2e test, which parses `timestamp(9)`, needs `spark.sql.timestampNanosTypes.enabled` on the server and failed only for that reason on the local server; that test is unchanged. - No crate that the Rust 1.88 MSRV job checks declares a `rust-version` above 1.88. - `cargo check --workspace --all-targets`, `cargo fmt`, `scripts/audit_no_stubs.sh`, and ruff 0.14.0 `check` and `format --check` pass. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Opus 5.5 This pull request and its description were written by Isaac. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
