[SPARK-48678][CORE] Performance optimizations for SparkConf.get(ConfigEntry)#47049
Closed
JoshRosen wants to merge 5 commits into
Closed
[SPARK-48678][CORE] Performance optimizations for SparkConf.get(ConfigEntry)#47049JoshRosen wants to merge 5 commits into
JoshRosen wants to merge 5 commits into
Conversation
HyukjinKwon
approved these changes
Jun 21, 2024
…ry.scala Co-authored-by: Hyukjin Kwon <gurwls223@gmail.com>
yaooqinn
approved these changes
Jun 21, 2024
mridulm
approved these changes
Jun 21, 2024
| (maybePrependedValue, value) match { | ||
| case (Some(prependedValue), Some(value)) => Some(s"$prependedValue$prependSeparator$value") | ||
| case (Some(prepend), None) => Some(prepend) | ||
| case (None, Some(value)) => Some(value) |
Contributor
There was a problem hiding this comment.
super nit: avoid shadowing value ? ... that would also allow us to simply return value for case 3 (and maybePrependedValue for case 2)
Contributor
Author
There was a problem hiding this comment.
Good idea.
I found that we can actually go a bit further and collapse all but the first case into a single case: if we don't match (Some(prependedValue), Some(value)) then we can just return value.orElse(prependedValue) since only one of the two options will be non-empty in that branch.
Member
|
Merged to master. |
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
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 two micro-optimizations for
SparkConf.get(ConfigEntry):Regex.replaceAllInfor variable substitution: if the config value does not contain the substring${then it cannot possibly contain any variables, so we can completely skip the regex evaluation in such cases.List.flattenandAbstractIterable.mkString, for the common case where a configuration does not define a prepended configuration key.Why are the changes needed?
Improve performance.
This is primarily motivated by unit testing and benchmarking scenarios but it will also slightly benefit production queries.
Spark tries to avoid excessive configuration reading in hot paths (e.g. via changes like #46979). If we do accidentally introduce such read paths, though, then this PR's optimizations will help to greatly reduce the associated perf. penalty.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Correctness should be covered by existing unit tests.
To measure performance, I did some manual benchmarking by running
followed by
10 million times in a loop.
On my laptop, the optimized code is ~7.5x higher throughput than the original.
We can also compare the before-and-after flamegraphs from a
while(true)configuration reading loop, showing a clear difference in hotspots before and after this change:Before:
After:
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Github Copilot