You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "itholic (via GitHub)" <gi...@apache.org> on 2025/02/17 07:09:35 UTC
[PR] [SPARK-51242][CONENCT][PYTHON] Improve Column performance when DQC is disabled [spark]
itholic opened a new pull request, #49982:
URL: https://github.com/apache/spark/pull/49982
### What changes were proposed in this pull request?
This PR proposes to improve Column performance when DQC(DataFrameQueryContext) is disabled by delaying to call `getActiveSession` which is pretty expensive.
### Why are the changes needed?
To improve the performance of Column operations.
### Does this PR introduce _any_ user-facing change?
No, API changes but only improves the performance
### How was this patch tested?
Manually tested, and also the existing CI should pass.
```python
>>> spark.conf.get("spark.python.sql.dataFrameDebugging.enabled")
'false'
```
**Before fix**
```python
>>> import time
>>> import pyspark.sql.functions as F
>>>
>>> c = F.col("name")
>>> start = time.time()
>>> for i in range(10000):
... _ = c.alias("a")
...
>>> print(time.time() - start)
2.061354875564575
```
**After fix**
```python
>>> import time
>>> import pyspark.sql.functions as F
>>>
>>> c = F.col("name")
>>> start = time.time()
>>> for i in range(10000):
... _ = c.alias("a")
...
>>> print(time.time() - start)
0.8050589561462402
```
And there is no difference when the flag is on:
```python
>>> spark.conf.get("spark.python.sql.dataFrameDebugging.enabled")
'true'
```
**Before fix**
```python
>>> import time
>>> import pyspark.sql.functions as F
>>>
>>> c = F.col("name")
>>> start = time.time()
>>> for i in range(10000):
... _ = c.alias("a")
...
>>> print(time.time() - start)
3.755108118057251
```
**After fix**
```python
>>> import time
>>> import pyspark.sql.functions as F
>>>
>>> c = F.col("name")
>>> start = time.time()
>>> for i in range(10000):
... _ = c.alias("a")
...
>>> print(time.time() - start)
3.6577670574188232
```
### Was this patch authored or co-authored using generative AI tooling?
No.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51242][CONENCT][PYTHON] Improve Column performance when DQC is disabled [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #49982:
URL: https://github.com/apache/spark/pull/49982#issuecomment-2667167678
Merged to master.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51242][CONENCT][PYTHON] Improve Column performance when DQC is disabled [spark]
Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #49982:
URL: https://github.com/apache/spark/pull/49982#discussion_r1957720371
##########
python/pyspark/errors/utils.py:
##########
@@ -268,6 +266,8 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
finally:
set_current_origin(None, None)
else:
+ spark = SparkSession.getActiveSession()
Review Comment:
`getActiveSession` is pretty expensive so we'd better call it only when `is_debugging_enabled()` is True.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51242][CONENCT][PYTHON] Improve Column performance when DQC is disabled [spark]
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #49982:
URL: https://github.com/apache/spark/pull/49982#discussion_r1957816031
##########
python/pyspark/errors/utils.py:
##########
@@ -268,6 +266,8 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
finally:
set_current_origin(None, None)
else:
+ spark = SparkSession.getActiveSession()
Review Comment:
yeah, we should always invoke SparkSession operations lazily
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51242][CONENCT][PYTHON] Improve Column performance when DQC is disabled [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #49982: [SPARK-51242][CONENCT][PYTHON] Improve Column performance when DQC is disabled
URL: https://github.com/apache/spark/pull/49982
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org