bhollis-dbx commented on code in PR #58865:
URL: https://github.com/apache/spark/pull/58865#discussion_r4125639479


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/trees/TreeNodeSuite.scala:
##########
@@ -99,6 +100,30 @@ case class FakeLeafPlan(child: LogicalPlan)
 case class FakeCurryingProduct(x: Expression)(val y: Int)
 
 class TreeNodeSuite extends SparkFunSuite with SQLHelper {
+  test("constructing unused Literals does not allocate eager cache state") {
+    val bean = 
ManagementFactory.getThreadMXBean.asInstanceOf[com.sun.management.ThreadMXBean]
+    assert(bean.isThreadAllocatedMemorySupported)
+    bean.setThreadAllocatedMemoryEnabled(true)
+    val count = 100000
+    val literals = new Array[Literal](count)
+
+    var i = 0
+    while (i < count) {
+      Literal(1)
+      i += 1
+    }
+
+    val before = bean.getCurrentThreadAllocatedBytes
+    i = 0
+    while (i < count) {
+      literals(i) = Literal(1)
+      i += 1
+    }
+    val bytesPerLiteral = (bean.getCurrentThreadAllocatedBytes - before) / 
count
+
+    assert(bytesPerLiteral < 220, s"unused Literal allocated $bytesPerLiteral 
bytes")

Review Comment:
   Replaced the allocation measurement with a direct assertion that all five 
cache fields remain uninitialized after constructing a node. This removes the 
JVM-specific threshold, MXBean dependency, global-state mutation, and dead-code 
risk.



-- 
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]

Reply via email to