perf: Cache jstrings during metrics collection#1029
Conversation
…locations. I need to confirm 1) there's actually a performance benefit to this, and 2) these GlobalRefs are being released when I want them to be.
|
I will update with some benchmark results tomorrow, but initial results look promising. |
|
The speedup on q4 is pretty impressive! Here are the raw JSON benchmark result files: |
|
Thanks for running the benchmarks for me. I was struggling to get reproducible results locally. |
|
edit: posted the wrong pngs from the wrong benchmark - updated now |
This seems correct to me |
|
I had earlier posted fresh benchmarks that showed a big improvement with the latest commit but I had inadvertently enabled the new |
Spark has a single thread calling |
* Attempt at caching Jstrings as GlobalRefs in a HashMap to reduce reallocations. I need to confirm 1) there's actually a performance benefit to this, and 2) these GlobalRefs are being released when I want them to be. * Minor refactor and added more docs. * Undo import reordering to reduce diff. * Docs. * Avoid get() by just cloning the Arc to globalref on insert. * Store jstring cache in ExecutionContext.


Which issue does this PR close?
Partially addresses #1024.
Rationale for this change
Comet uses JNI jstrings as the keys to updating metrics values on the Spark side during execution. As described in #1024, currently Comet allocates a jstring for every metric for every invocation of metrics updating. The calls to
jni_NewStringUTFaccount for over 1% of the on-CPU time in TPC-H SF10 for me.What changes are included in this PR?
Added a HashMap that maps the native string to a jstring to use in JNI calls. This has the benefit of being many-to-one, whereby multiple nodes with the same metric name will benefit from the cached jstring. This cache is populated on demand: if the entry isn't present, we allocate a jstring and insert it into the cache.
I have some thoughts about this approach that I would love for reviewers to comment on:
ExecutePlan. However, DF's metrics are Options and don't actually appear to be there until the plan starts executing.How are these changes tested?
Existing tests on the Java side that exercise metrics.