You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Codegen dispatcher: avoid copying and hashing the serialized expression on every batch #6705
On every batch, CometScalaUDFCodegen.evaluate copies the serialized bound expression out of its first argument (exprVec.get(0)), about 7 KB for a simple Scala UDF, and hashes the copy into the kernel cache key. The perf-cache-key TODO on CometScalaUDFCodegen.CacheKey already describes this.
@mbutrovich measured it on #6697 (comment). He found a fixed cost of about 8 microseconds per batch in the dispatcher, about 4 ms over 4M rows at batch size 8192, which grows as batches get smaller. About 6 microseconds of it is the difference between calling CometScalaUDFCodegen.evaluate and calling its generated kernel directly, which is where the copy and the hash happen.
Describe the potential solution
Compute a hash, or another identifier for the expression, on the driver and ship it through the JvmScalarUdf proto, so that a batch looks the kernel up without copying or hashing the closure. The TODO lists other options: per-instance memoization of the last key, or a two-tier cache keyed on the generated source.
Additional context
The measurements and the benchmark source are in the comment linked above.
Activity
perf: key the codegen dispatcher's kernel cache on a digest of the ex…