Short version: What is the overhead of a cranelift::JITModule ? Can we afford to have one per function ?
Longer version:
I'm referring to https://github.com/bytecodealliance/wasmtime/blob/e6f399419c60c0306d13e39c2f955090f7da943f/cranelift/jit/src/backend.rs#L146-L165 , but size-of may not be accurate as there may be dynamically allocated stuff JITModule::new() creates
XY problem:
When we use cranelift as a JIT backend, we need to call get_finalized_function
to get the actual function. I believe this results in a memory leak unless we call JITModule::free_memory. See: https://github.com/bytecodealliance/wasmtime/blob/e6f399419c60c0306d13e39c2f955090f7da943f/cranelift/jit/src/backend.rs#L350-L354
The issue here is that JITModule::free_memory appears to nuke the entire module, and there is no way to free an individual function.
Therefore, I am considering having a JITModule per JIT-ted function. Thus, the question: how expensive is as JITModule, and can we afford to have one per JIT-ted function ?