You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Wenchen Fan (Jira)" <ji...@apache.org> on 2026/06/23 15:45:00 UTC

[jira] [Resolved] (SPARK-57593) Python UDF: instrument and byte-bound the pickle input batch

     [ https://issues.apache.org/jira/browse/SPARK-57593?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Wenchen Fan resolved SPARK-57593.
---------------------------------
    Fix Version/s: 4.3.0
       Resolution: Fixed

Issue resolved by pull request 56649
[https://github.com/apache/spark/pull/56649]

> Python UDF: instrument and byte-bound the pickle input batch
> ------------------------------------------------------------
>
>                 Key: SPARK-57593
>                 URL: https://issues.apache.org/jira/browse/SPARK-57593
>             Project: Spark
>          Issue Type: Task
>          Components: PySpark
>    Affects Versions: 4.2.0
>            Reporter: Tengfei Huang
>            Assignee: Tengfei Huang
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 4.3.0
>
>
> For a regular (non-Arrow, pickle-serialized) Python UDF, `BatchEvalPythonExec` groups input rows into batches purely by row count (`spark.sql.execution.python.udf.maxRecordsPerBatch`, default 100) and pickles the whole batch into one contiguous byte array before sending it to the Python worker.
> When the rows are wide (large strings, binary, or decimal columns), a single row-count batch can be very large, so the JVM must buffer one oversized pickled array on the heap -- amplified by the `ByteArrayOutputStream` power-of-two grow-copy and the final toByteArray copy (~2x transient). On memory-constrained executors this can drive the executor into an `OutOfMemoryError`, with no way to bound it other than lowering the row count for every UDF.
> The Arrow Python UDF path already byte-bounds its batches (it checks arrowWriter.sizeInBytes() per row and slices before crossing the limit). The pickle path has no equivalent: it is bounded only by row count. To avoid memory issues crashing executor, we should also bound the batch by size for pickle-serialized UDF.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org