-
Notifications
You must be signed in to change notification settings - Fork 12.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rustc uses insane amounts of memory when compiling a function that loads 1500+ function pointers from a DLL #73510
Comments
According to |
as a workaround, this reduces peak memory consumption for the provided testcase to 1.5GB: [profile.dev]
incremental = false |
Well, I just created a "mini" version of libloading that only uses the raw I pushed a I'm don't know what the correct command for showing |
Your new example calls |
The mini branch does not build
|
@the8472 Fixed it, try again. However, I didn't even get that far when running cargo check, that's why I didn't notice the error. |
With the fix it compiles in 6s. |
It seems that one workaround is to put the function-pointer loading code into separate functions. If I generate hundreds of small functions instead of putting everything in one big function, it compiles fast (well, still 10 seconds on my laptop, but at least I can get it to compile at all): // compiles fast
unsafe fn load_fn_570(lib: &Library) -> Option<fn(_: _570) -> _571> {
Some(mem::transmute(lib.get(b"function_570")?))
}
unsafe fn load_fn_571(lib: &Library) -> Option<fn(_: _571) -> _572> {
Some(mem::transmute(lib.get(b"function_571")?))
}
// compiles fast
fn load_dll() -> Option<Dll> {
// <...>
let function_570 = load_fn_570(&lib)?;
let function_571 = load_fn_571(&lib)?;
// <...>
} instead of: // compiles slow
fn load_dll() -> Option<Dll> {
// <...>
let function_570: fn(_: _570) -> _571 = mem::transmute(lib.get(b"function_570")?);
let function_571: fn(_: _571) -> _572 = mem::transmute(lib.get(b"function_571")?);
// <...>
} |
Wait, nevermind, the second approach is slower (9s vs 7s). |
For my use-case, I'm trying to load a lot of function pointers from a .dll file using the
libloading
crate. However, I can't compile aload_my_dll()
function if I have more than maybe 1000 function pointers, because rustc uses an insane amount of memory for compilation:I can pretty much watch my computer lock up in real time because it runs out of memory (see the pie in the lower left corner).
I've built a test-case here: https://github.com/fschutt/libloading-loadtest
Look in the
generate.py
file, I've currently set it to 2000 function pointers, but that's not even a lot. Larger DLLs will likely need 5000 - 30000 function pointers. Clone the repository and runcargo check
. After you wait a while, the memory usage will go up dramatically. This bug also happens on nightly.I think this may have to do with how verbose the code output of generics are. Is there a way to fix it from my side?
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: