-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-50685][PYTHON] Improve Py4J performance by leveraging getattr #49313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xinrong-meng
approved these changes
Dec 27, 2024
ueshin
approved these changes
Dec 27, 2024
zhengruifeng
approved these changes
Dec 27, 2024
Member
Author
|
Merged to master. |
HyukjinKwon
added a commit
that referenced
this pull request
Jan 9, 2025
…ng getattr ### What changes were proposed in this pull request? This PR is. a followup of #49313 that fixes more places missed. This PR fixes Core, SQL, ML and Structured Streaming. Tests codes, MLLib and DStream are not affected. ### Why are the changes needed? To reduce the overhead of Py4J calls. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Manually tested as demonstrated in #49312 ### Was this patch authored or co-authored using generative AI tooling? No. Closes #49412 from HyukjinKwon/SPARK-50685-followup. Authored-by: Hyukjin Kwon <gurwls223@apache.org> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
HyukjinKwon
pushed a commit
that referenced
this pull request
Feb 4, 2025
### What changes were proposed in this pull request? Avoids using `jvm.SparkSession` style, to improve Py4J performance similar to #49312, #49313, and #49412. ### Why are the changes needed? To reduce the overhead of Py4J calls. ```py import time def benchmark(f, _n=10, *args, **kwargs): start = time.time() for i in range(_n): f(*args, **kwargs) print(time.time() - start) ``` ```py from pyspark.context import SparkContext jvm = SparkContext._jvm def f(): return jvm.SparkSession benchmark(f, 10000) # -> 3.578310251235962 ``` ```py from pyspark.context import SparkContext jvm = SparkContext._jvm def g(): return getattr(jvm, "org.apache.spark.sql.classic.SparkSession") benchmark(g, 10000) # -> 0.254807710647583 ``` ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? The existing tests should pass. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #49760 from ueshin/issues/SPARK-51058/spark_session. Authored-by: Takuya Ueshin <ueshin@databricks.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
HyukjinKwon
pushed a commit
that referenced
this pull request
Feb 4, 2025
### What changes were proposed in this pull request? Avoids using `jvm.SparkSession` style, to improve Py4J performance similar to #49312, #49313, and #49412. ### Why are the changes needed? To reduce the overhead of Py4J calls. ```py import time def benchmark(f, _n=10, *args, **kwargs): start = time.time() for i in range(_n): f(*args, **kwargs) print(time.time() - start) ``` ```py from pyspark.context import SparkContext jvm = SparkContext._jvm def f(): return jvm.SparkSession benchmark(f, 10000) # -> 3.578310251235962 ``` ```py from pyspark.context import SparkContext jvm = SparkContext._jvm def g(): return getattr(jvm, "org.apache.spark.sql.classic.SparkSession") benchmark(g, 10000) # -> 0.254807710647583 ``` ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? The existing tests should pass. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #49760 from ueshin/issues/SPARK-51058/spark_session. Authored-by: Takuya Ueshin <ueshin@databricks.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org> (cherry picked from commit 2581ca1) Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
zifeif2
pushed a commit
to zifeif2/spark
that referenced
this pull request
Nov 14, 2025
### What changes were proposed in this pull request? Avoids using `jvm.SparkSession` style, to improve Py4J performance similar to apache#49312, apache#49313, and apache#49412. ### Why are the changes needed? To reduce the overhead of Py4J calls. ```py import time def benchmark(f, _n=10, *args, **kwargs): start = time.time() for i in range(_n): f(*args, **kwargs) print(time.time() - start) ``` ```py from pyspark.context import SparkContext jvm = SparkContext._jvm def f(): return jvm.SparkSession benchmark(f, 10000) # -> 3.578310251235962 ``` ```py from pyspark.context import SparkContext jvm = SparkContext._jvm def g(): return getattr(jvm, "org.apache.spark.sql.classic.SparkSession") benchmark(g, 10000) # -> 0.254807710647583 ``` ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? The existing tests should pass. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#49760 from ueshin/issues/SPARK-51058/spark_session. Authored-by: Takuya Ueshin <ueshin@databricks.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org> (cherry picked from commit 03c93e1) Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This Pr proposes to improve Py4J performance by leveraging
getattr, see also #46809This PR fixes Core, SQL, ML and Structured Streaming. Tests codes, MLLib and DStream are not affected.
Why are the changes needed?
To reduce the overhead of Py4J calls.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Manually tested as demonstrated in #49312
Was this patch authored or co-authored using generative AI tooling?
No.