-
-
Notifications
You must be signed in to change notification settings - Fork 19
Enable link-time optimization when building Rust library for production #1
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
base: main
Are you sure you want to change the base?
Conversation
61ae68d
to
9c5e197
Compare
Cool, thanks. Before I merge this I have a question. Have you noticed any regressions in compile times? A little increase is fine, but I'd rather not have compile times that increase significantly... Also, do these flags work on Windows as well? |
I haven't done thorough benchmarking, but I'd expect a release build to take 30 seconds to 1 minute longer. This doesn't impact debug builds where you do most of the development anyway.
They should, but I haven't tested them there. |
Hmm just tested it, compile times increase significantly, going from ~15 sec to ~1 minute on my 4th gen i5 CPU. I'd love to use this for the final binary, but having this enabled during development really hinders my development speed. Do you think there is any way to somehow only enable this flag when publishing the final binary? E.g. I have a |
Are you sure this affects build times when using It's possible to set build flags in the build script, but I'd prefer if this was always done for release builds. |
I always develop in release mode, because 1. it gives me a better picture of the real world performance of my program during development (profiling should always be done in release mode), and 2. I don't have to worry about accidentally copying the wrong DLL and shipping debug builds. If I need to debug something I can use the trusty I think I'll go for the environment variable for now, to avoid slowing down development. Update: just tested running in debug mode, it doesn't even work on my end 😄 Getting a bazillion linker errors everywhere. Not sure if that's a configuration problem, I'll have to look into it. |
This decreases the compiled library size and improves performance. codegen-units is also set to 1 to further optimize the compiled library.
9c5e197
to
7743366
Compare
@Bauxitedev Could you test the |
I'll check it out soon. You can ignore the dockerfile for now, I used it for testing purposes only, it doesn't serve any purpose anymore. |
Just tested, the python build script doesn't seem to work for me. The
It seems to be trying to create a temp directory in the Windows folder, even though it doesn't have permission to do so (the script shouldn't run with admin privileges). Any ideas? Also it would be nice if the script stopped entirely if this step fails (easy fix, just add |
This decreases the compiled library size and improves performance.
codegen-units
is also set to 1 to further optimize the compiled library.There's more advice here: https://likebike.com/posts/How_To_Write_Fast_Rust_Code.html
Note: I haven't tried to run the Godot project as a whole with these changes. It's likely that it will work as-is, but I recommend cloning this branch locally to test before merging.
Preview
Linux x86_64 (rustc nightly from 2021-03-26). Both libraries had their debug symbols removed by running
strip
on them.Before (LTO disabled,
codegen-units = 16
)After (LTO enabled,
codegen-units = 16
)After (LTO enabled,
codegen-units = 1
) – this PR