Skip to content

Commit ceeb661

Browse files
authored
aotcompile: destroy LLVM context after serializing combined module (JuliaLang#59329)
We already save some memory here by deleting the `jl_native_code_desc_t` after we're done serializing the combined module, but some data in the module's `LLVM::Context` lives on until the end of the scope in `jl_dump_native_impl`. Once we're done with the module, move the lock and `ThreadSafeContext` so the reference count drops to zero. A crude measurement shows that when compiling the Base sysimage, about 3 GiB is in use. Deleting the `jl_native_code_desc_t` (as before) saves about 600 MiB, and cleaning up the context saves an additional ~500 MiB.
1 parent c6e7650 commit ceeb661

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/aotcompile.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,9 +2271,14 @@ void jl_dump_native_impl(void *native_code,
22712271
auto lock = TSCtx.getLock();
22722272
auto dataM = data->M.getModuleUnlocked();
22732273

2274-
// Delete data when add_output thinks it's done with it
2275-
// Saves memory for use when multithreading
2276-
data_outputs = compile(*dataM, "text", threads, [data](Module &) { delete data; });
2274+
data_outputs = compile(*dataM, "text", threads, [data, &lock, &TSCtx](Module &) {
2275+
// Delete data when add_output thinks it's done with it
2276+
// Saves memory for use when multithreading
2277+
auto lock2 = std::move(lock);
2278+
delete data;
2279+
// Drop last reference to shared LLVM::Context
2280+
auto TSCtx2 = std::move(TSCtx);
2281+
});
22772282
}
22782283

22792284
if (params->emit_metadata) {

0 commit comments

Comments
 (0)