Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-48678][CORE] Performance optimizations for SparkConf.get(Confi…
…gEntry) ### What changes were proposed in this pull request? This PR proposes two micro-optimizations for `SparkConf.get(ConfigEntry)`: 1. Avoid costly `Regex.replaceAllIn` for 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. 2. Avoid Scala collections operations, including `List.flatten` and `AbstractIterable.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 ``` val conf = new SparkConf() conf.set("spark.network.crypto.enabled", "true") ``` followed by ``` conf.get(NETWORK_CRYPTO_ENABLED) ``` 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**: ![image](https://github.com/apache/spark/assets/50748/a60cec03-2400-46a5-95f5-f33b88a4872a) **After**: ![image](https://github.com/apache/spark/assets/50748/10a45575-148b-4f5f-a431-b8036fe59866) ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Github Copilot Closes #47049 from JoshRosen/SPARK-48678-sparkconf-perf-optimizations. Authored-by: Josh Rosen <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
- Loading branch information