zeruibao commented on code in PR #52391:
URL: https://github.com/apache/spark/pull/52391#discussion_r2396503725


##########
python/pyspark/sql/pandas/serializers.py:
##########
@@ -1630,8 +1633,23 @@ def row_stream():
                         yield (batch_key, row)
 
             for batch_key, group_rows in groupby(row_stream(), key=lambda x: 
x[0]):
-                df = pd.DataFrame([row for _, row in group_rows])
-                yield (batch_key, df)
+                rows = []
+                accumulate_size = 0
+                for _, row in group_rows:
+                    rows.append(row)
+                    # Short circuit batch size calculation if the batch size is
+                    # unlimited as computing batch size is computationally 
expensive.
+                    if self.arrow_max_bytes_per_batch != 2**31 - 1:
+                        accumulate_size += sum(sys.getsizeof(x) for x in row)

Review Comment:
   I got a better idea. It would be to compute the average row size for each 
Arrow RecordBatch. When accumulating rows into a Pandas DataFrame, we can then 
use this average row size as an estimate for the DataFrame row, avoiding the 
need to measure each individual row. Then we can still use this 
`arrow_max_bytes_per_batch` config and it's more accurate than `sys.getsizeof` 
cc: @HeartSaVioR



-- 
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]

Reply via email to