Hi Calcite devs, Our team caches compiled Bindables in our service, and we've noticed excessive heap usage as the number of cached plans grows. Most of this seems to come from generated bytecode that’s kept alive longer than needed.
Digging in a bit, we see that EnumerableInterpretable#getBindable loads the generated classes through Janino's ByteArrayClassLoader [1][2]. It looks like this loader keeps the bytecode of every generated class in a map and never removes entries from it [3], meaning a cached Bindable (e.g. in BINDABLE_CACHE) keeps all of its bytecode on the heap (even though it is no longer needed once the classes are loaded). In a rough local benchmark on a sample of our plans, this bytecode made up most of the heap retained by each cached Bindable. Have you encountered this before, and/or is it a known issue? The closest related item we found is CALCITE-1885 [4], but that’s about generated classes not being unloaded. Best, Austin [1] EnumerableInterpretable#getBindable <https://github.com/apache/calcite/blob/calcite-1.42.0/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableInterpretable.java#L134-L181> [2] SimpleCompiler#getClassLoader <https://github.com/janino-compiler/janino/blob/v3.1.12/janino/src/main/java/org/codehaus/janino/SimpleCompiler.java#L337-L361> [3] ByteArrayClassLoader#findClass <https://github.com/janino-compiler/janino/blob/v3.1.12/commons-compiler/src/main/java/org/codehaus/commons/compiler/util/reflect/ByteArrayClassLoader.java#L73-L102> [4] CALCITE-1885 <https://issues.apache.org/jira/browse/CALCITE-1885>
