Github user chenghao-intel commented on the pull request: https://github.com/apache/spark/pull/5154#issuecomment-85569221 Verified the code change by the following micro-benchmark ```scala import org.apache.spark.sql.catalyst.expressions._ import org.apache.spark.sql.types._ case class Floor(child: Expression) extends UnaryExpression with Predicate { override def foldable = child.foldable def nullable = child.nullable override def toString = s"Floor $child" override def eval(input: Row): Any = { child.eval(input) match { case null => null case ts: Int => ts - ts % 300 } } } object T { def benchmark(count: Int, expr: Expression): Unit = { var i = 0 val row = new GenericRow(Array[Any](123, 21, 42)) val s = System.currentTimeMillis() while (i < count) { expr.eval(row) i += 1 } val e = System.currentTimeMillis() println (s"${expr.getClass.getSimpleName} -- ${e - s} ms") } def main(args: Array[String]) { def func(ts: Int) = ts - ts % 300 val udf0 = ScalaUdf(func _, IntegerType, BoundReference(0, IntegerType, true) :: Nil) val udf1 = Floor(BoundReference(0, IntegerType, true)) benchmark(1000000, udf0) benchmark(1000000, udf0) benchmark(1000000, udf0) benchmark(1000000, udf1) benchmark(1000000, udf1) benchmark(1000000, udf1) } } ``` Without the code change it outputs ScalaUdf -- 1183 ms ScalaUdf -- 887 ms ScalaUdf -- 929 ms Floor -- 49 ms Floor -- 15 ms Floor -- 21 ms With the code change, it outputs ScalaUdf -- 382 ms ScalaUdf -- 255 ms ScalaUdf -- 247 ms Floor -- 27 ms Floor -- 6 ms Floor -- 8 ms Conclusions: * The code change will improve the performance of scala udf by 2-3x * Scala UDF is in very low performance compare to the built-in type of Expression. We probably need to provide more efficient way of UDF extension interface.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org