Skip to content

[SPARK-58683][ML] Optimize NGram transform closure - #57886

Closed
zhengruifeng wants to merge 2 commits into
apache:masterfrom
zhengruifeng:SPARK-58683-ngram-transform-state
Closed

[SPARK-58683][ML] Optimize NGram transform closure#57886
zhengruifeng wants to merge 2 commits into
apache:masterfrom
zhengruifeng:SPARK-58683-ngram-transform-state

Conversation

@zhengruifeng

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Snapshot the configured n-gram size while creating NGram's transform function. The resulting function no longer captures the NGram transformer.

The serialized transform function decreases from 2,988 bytes to 1,277 bytes (57.3%).

Why are the changes needed?

Avoiding the transformer capture reduces the memory retained by the transform closure, which is especially useful for Spark Connect server workloads.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Compiled the edited NGram source and serialized its generated transform function with Java serialization. The existing NGramSuite covers the unchanged transform behavior.

The targeted SBT suite could not run locally because dependency resolution for at.yawk:lz4-java:1.11.2 was denied by the configured Maven mirror.

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

Generated-by: Codex (GPT-5)

@uros-b

uros-b commented Aug 10, 2026

Copy link
Copy Markdown
Member

Thank you @zhengruifeng!

@zhengruifeng zhengruifeng changed the title [SPARK-58683][ML] Avoid capturing NGram transformation state [SPARK-58683][ML] Optimize NGram transform closure Aug 10, 2026
zhengruifeng added a commit that referenced this pull request Aug 10, 2026
### What changes were proposed in this pull request?

Snapshot the configured n-gram size while creating NGram's transform function. The resulting function no longer captures the NGram transformer.

The serialized transform function decreases from 2,988 bytes to 1,277 bytes (57.3%).

### Why are the changes needed?

Avoiding the transformer capture reduces the memory retained by the transform closure, which is especially useful for Spark Connect server workloads.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Compiled the edited NGram source and serialized its generated transform function with Java serialization. The existing NGramSuite covers the unchanged transform behavior.

The targeted SBT suite could not run locally because dependency resolution for `at.yawk:lz4-java:1.11.2` was denied by the configured Maven mirror.

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

Generated-by: Codex (GPT-5)

Closes #57886 from zhengruifeng/SPARK-58683-ngram-transform-state.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
(cherry picked from commit c0d4dda)
Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
@zhengruifeng

Copy link
Copy Markdown
Contributor Author

Merge Summary:

Posted by merge_spark_pr.py

@zhengruifeng
zhengruifeng deleted the SPARK-58683-ngram-transform-state branch August 10, 2026 12:14
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