hussein-awala opened a new pull request, #59341: URL: https://github.com/apache/spark/pull/59341
### What changes were proposed in this pull request? Reuse a private, shared compiled `Exec$` pattern in `TreeNode.nodeName`, creating a fresh matcher for each invocation. Add a focused regression test in `TreeNodeSuite` and a generic `TreeNodeBenchmark`. Keep `Utils.getSimpleName`, its malformed-class-name fallback, and the overridable `nodeName` method unchanged. No per-node cache or mutable shared matcher is introduced. JIRA: https://issues.apache.org/jira/browse/SPARK-60136 ### Why are the changes needed? `String.replaceAll` compiles the same pattern on every invocation, including calls whose input has no match. Sharing the immutable pattern avoids that compilation and allocation work. Literal `stripSuffix("Exec")` is not an exact substitute: Java's `$` also matches before a final line terminator, and legal JVM class names can contain these characters. Retaining the same compiled pattern preserves those semantics. ### Does this PR introduce _any_ user-facing change? No. Name lookup, matching semantics, replacement and virtual overrides retain their existing behavior, including the fallback covered by SPARK-32999. ### How was this patch tested? Local JDK 21.0.8 validation: ```sh export HEAP_SIZE=4g export JAVA_TOOL_OPTIONS=-XX:ActiveProcessorCount=2 build/sbt -batch -no-colors -J-Xmx4g -J-XX:ActiveProcessorCount=2 \ 'catalyst/Compile/scalastyle' 'catalyst/Test/scalastyle' \ 'catalyst/testOnly org.apache.spark.sql.catalyst.trees.TreeNodeSuite' \ 'catalyst/Test/runMain org.apache.spark.sql.catalyst.trees.TreeNodeBenchmark' ``` - All 37 `TreeNodeSuite` tests passed. - The new test checks 32 generated JVM names and an anonymous node against explicit expected values and the old expression. - Cases include absent/repeated/embedded suffixes, case differences, dollar-ending names, final LF/CR/CRLF/NEL/line-separator/paragraph-separator, doubled/interior terminators and nonmatching whitespace. ASM is used for names that cannot be expressed as ordinary Java/Scala identifiers. - Both ScalaStyle checks passed with no errors or warnings. Generic synthetic-node benchmark, local best nanoseconds per call: | Case | Original expression | Shared pattern | |---|---:|---:| | No `Exec` suffix | 78.3 | 19.4 | | With `Exec` suffix | 92.5 | 40.0 | The benchmark uses identical iteration counts and volatile result consumption, with no SparkSession or data source. These are local CPU microbenchmark observations, not end-to-end performance or allocation-byte measurements. Fresh matcher allocation remains. The full Spark matrix and standardized CI benchmark workflow have not been run. This PR is intentionally a draft. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Pi Coding Agent 1.1.0 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
