This is an automated email from the ASF dual-hosted git repository.
HyukjinKwon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark-connect-rust.git
The following commit(s) were added to refs/heads/master by this push:
new cfc44775 [SPARK-61457][CONNECT][PYTHON] Mark PySpark Column as frozen
cfc44775 is described below
commit cfc4477523b1131fe06e043ace447ea7ca948102
Author: Ruifeng Zheng <[email protected]>
AuthorDate: Thu Nov 12 07:05:12 2026 +0900
[SPARK-61457][CONNECT][PYTHON] Mark PySpark Column as frozen
### What changes were proposed in this pull request?
Mark the PyO3 `Column` class as `frozen`.
`Column` has no mutable Rust methods, setters, or `PyRefMut` use. The
existing `dict` and `weakref` support remains enabled, so Python dynamic
attributes and weak references continue to work.
### Why are the changes needed?
PyO3 can access a frozen class payload without runtime mutable-borrow
checks. `Column` is used throughout Python expression construction, so
declaring its existing immutability invariant reduces overhead on direct
payload access and extraction.
A Python 3.13 release-mode microbenchmark used 300,000 calls per case,
median times from 9 and 11 rounds, fresh processes, and both baseline/frozen
execution orders. Results were:
| Operation | Baseline | Frozen | Speedup |
| --- | ---: | ---: | ---: |
| Rust helper extracting `Column` | 127-131 ns | 120-124 ns | 5.4-5.9% |
| `column._expr` getter | 108.5-110.2 ns | 104.0-104.4 ns | 4.1-5.3% |
| `repr(column)` | 132.6-137.5 ns | 128.4-129.3 ns | 2.4-6.7% |
Higher-level expression-building operations were dominated by allocation
and expression construction and did not show a stable end-to-end difference in
this microbenchmark.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
- `cargo fmt --all --check`
- `cargo build -p pyspark-rs --release`
- `cargo test -p apache-spark-connect --release --lib` (602 passed)
- `cargo test -p apache-spark-connect --release --no-run`
- `cargo test -p apache-spark-connect --release --features wasm-udf
--no-run`
- Offline Python suites: 3,118 passed, 8 skipped, 14 subtests passed
- Verified Python dynamic attributes and weak references on `Column`
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Codex (GPT-5)
This pull request and its description were written by Isaac.
Closes #516 from zhengruifeng/optimize-frozen-column.
Authored-by: Ruifeng Zheng <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
---
crates/pyspark-rs/src/column.rs | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/crates/pyspark-rs/src/column.rs b/crates/pyspark-rs/src/column.rs
index d18ec4cf..fe22b0f5 100644
--- a/crates/pyspark-rs/src/column.rs
+++ b/crates/pyspark-rs/src/column.rs
@@ -37,7 +37,13 @@ pub(crate) fn column_reference_name(column: PyRef<'_,
PyColumn>) -> Option<Strin
}
/// Python wrapper for a Spark Column.
-#[pyclass(name = "Column", module = "pyspark.sql.connect.column", weakref,
dict)]
+#[pyclass(
+ frozen,
+ name = "Column",
+ module = "pyspark.sql.connect.column",
+ weakref,
+ dict
+)]
pub struct PyColumn {
pub(crate) column: Column,
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]