The difference is closure invocation
instead of a static java.lang.Math call. In many cases JIT may not
be able to perform inlining and related code optimizations though
in this specific case it should. This is highly dependent on the
specific case, but when inlining cannot be done and it leads to a
method call (especially virtual call) then the difference is quite
large: few nanoseconds per evaluation vs tens of nanoseconds in my
experiments.
Serialization of an additional object as a reference can have a measurable effect for low-latency jobs though usually can be ignored. What has been observed is that if an _expression_ uses CodegenFallback then it becomes an order of magnitude slower or more. Most of it is due to UnsafeRow read/write overhead which is avoided here, but still care needs to be taken for (virtual) function calls too. In some cases JIT does inline virtual calls but may not always happen. In my experience the only reliable case where it does inline is when the virtual call is on a local variable that does not change for multiple invocations (e.g. a final local variable outside the while loop of a doProduce). I think what should work better is encapsulating such code in methods of a scala object rather than a class and those can be invoked in generated code like static methods. Such calls should be equivalent to inline code generation in most cases since JIT will inline the calls where it will determine significant benefit. In some cases such method calls will have better CPU instruction cache hits (i.e. if same inline code is emitted multiple times vs common method calls). All this needs thorough micro/macro-benchmarking. However, I don't recall any large pieces of generated code where this can help. Most complex pieces like in HashAggregateExec/SortMergeJoinExec/BroadcastHashJoinExec are so because they generate schema specific code (to avoid virtual calls and boxing/unboxing, and UnsafeRow read/write in some cases) which is significantly faster than the equivalent generic code in doExecute. Or in your "castToDateCode" example, don't see how you can reduce it since bulk of code is already in the static stringToDate call. On Saturday 11 February 2017 03:02 AM, Koert Kuipers wrote:
--------------------------------------------------------------------- To unsubscribe e-mail: dev-unsubscr...@spark.apache.org |
- benefits of code gen Koert Kuipers
- Re: benefits of code gen Reynold Xin
- Re: benefits of code gen Koert Kuipers
- Re: benefits of code gen Michael Armbrust
- Re: benefits of code gen Koert Kuipers
- Re: benefits of code gen Sumedh Wale
- Re: benefits of code gen Koert Kuipers