Skip to content

[SPARK-58854][ML] Optimize GeneralizedLinearRegressionModel transform closure - #58100

Open
zhengruifeng wants to merge 1 commit into
apache:masterfrom
zhengruifeng:spark-58854-glr-transform-closure
Open

[SPARK-58854][ML] Optimize GeneralizedLinearRegressionModel transform closure#58100
zhengruifeng wants to merge 1 commit into
apache:masterfrom
zhengruifeng:spark-58854-glr-transform-closure

Conversation

@zhengruifeng

@zhengruifeng zhengruifeng commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR optimizes GeneralizedLinearRegressionModel.transform by snapshotting the prediction
state before creating transform UDFs. The UDFs now capture only the required coefficients,
intercept, and FamilyAndLink instead of the full model.

The public prediction methods continue to use the same prediction logic through companion helper
methods.

Why are the changes needed?

Avoiding the model capture reduces transform-closure retained memory, which is useful for Spark
Connect server workloads and follows the closure-size optimizations tracked under SPARK-58584.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Ran local static checks:

git diff --check
grep -rn -P "[^\x00-\x7F]" mllib/src/main/scala/org/apache/spark/ml/regression/GeneralizedLinearRegression.scala
awk 'length>100 && $0 !~ /^[[:space:]]*(import|package) / && $0 !~ /https?:\/\// {print FILENAME":"FNR": "length" chars"}' mllib/src/main/scala/org/apache/spark/ml/regression/GeneralizedLinearRegression.scala

Measured serialized ScalaUDF.function closure size with a temporary local probe:

Case Before After Delta
directPrediction 6753 B 3033 B -3720 B, -55.1%
linkAndPrediction total 13450 B 9559 B -3891 B, -28.9%

For linkAndPrediction, the two UDF closures measured individually as:

UDF Before After Delta
udf#0 6669 B 7482 B +813 B, +12.2%
udf#1 6781 B 2077 B -4704 B, -69.4%

No unit test was added because this is an internal refactor of existing prediction logic.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Codex (GPT-5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants