You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "ueshin (via GitHub)" <gi...@apache.org> on 2025/07/14 23:06:11 UTC
[PR] [SPARK-52796][PYTHON] Optimize LocalDataToArrowConversion.convert to improve its performance [spark]
ueshin opened a new pull request, #51482:
URL: https://github.com/apache/spark/pull/51482
### What changes were proposed in this pull request?
Improves the performance of `LocalDataToArrowConversion.convert`.
- Reduce the number of `isinstance` call
- Calculate `len(column_names)` in advance
- Separate creation of `rows` and conversion to avoid expensive `list.append` calls
- Reorder `isinstance` check to likely to rarely
- Make creation of `rows` for-comprehension to avoid expensive `list.append` calls
### Why are the changes needed?
`LocalDataToArrowConversion.convert` has several performance overhead.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
The existing tests, and manual benchmarks.
```py
def profile(f, _n=10, *args, **kwargs):
import cProfile
import pstats
import gc
st = None
for _ in range(5):
f(*args, **kwargs)
for _ in range(_n):
gc.collect()
with cProfile.Profile() as pr:
ret = f(*args, **kwargs)
if st is None:
st = pstats.Stats(pr)
else:
st.add(pstats.Stats(pr))
st.sort_stats("time", "cumulative").print_stats()
return ret
from pyspark.sql.conversion import LocalDataToArrowConversion
from pyspark.sql.types import *
data = [
(i if i % 1000 else None, str(i), i)
for i in range(1000000)
]
schema = (
StructType()
.add("i", IntegerType(), nullable=True)
.add("s", StringType(), nullable=True)
.add("ii", IntegerType(), nullable=False)
)
def test():
LocalDataToArrowConversion.convert(data, schema, use_large_var_types=False)
profile(test)
```
- before
```
140001570 function calls in 15.355 seconds
```
- after
```
70001580 function calls in 4.845 seconds
```
### 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-52796][PYTHON] Optimize LocalDataToArrowConversion.convert to improve its performance [spark]
Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin closed pull request #51482: [SPARK-52796][PYTHON] Optimize LocalDataToArrowConversion.convert to improve its performance
URL: https://github.com/apache/spark/pull/51482
--
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-52796][PYTHON] Optimize LocalDataToArrowConversion.convert to improve its performance [spark]
Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on PR #51482:
URL: https://github.com/apache/spark/pull/51482#issuecomment-3075479538
Thanks! merging 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