Skip to content
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

Reuse LTO products for incremental builds when deps are unchanged #71850

Open
fenollp opened this issue May 3, 2020 · 5 comments
Open

Reuse LTO products for incremental builds when deps are unchanged #71850

fenollp opened this issue May 3, 2020 · 5 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries C-enhancement Category: An issue proposing an enhancement or a PR with one. I-compiletime Issue: Problems and improvements with respect to compile times. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fenollp
Copy link

fenollp commented May 3, 2020

Incremental builds with LTO (thin or fat) always take the same amount of time (~10s on my project) when dependencies are unchanged. It seems to take as long when adding a dependency.

Is it not possible to cache (at least part) of the LTO computations?

Note I'm using cross:

# cross version
cargo 1.44.0-nightly (8751eb301 2020-04-21)

Note also this bug I've encountered WRT LTO: cross-rs/cross#416

#71248 is the most recent issue I could find that seems related.

@Alexendoo Alexendoo added C-enhancement Category: An issue proposing an enhancement or a PR with one. I-compiletime Issue: Problems and improvements with respect to compile times. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-linkage Area: linking into static, shared libraries and binaries labels May 6, 2020
@pnkfelix
Copy link
Member

pnkfelix commented Jun 2, 2020

To be clear: You're describing a scenario where your current crate is changed, but the dependencies are unchanged, right?

@fenollp
Copy link
Author

fenollp commented Jun 2, 2020

@pnkfelix Yep: changing some of the crate's code while deps are unchanged (LTO setting unchanged) takes a while to compile (incrementally).

@bjorn3
Copy link
Member

bjorn3 commented Jul 13, 2023

For fat LTO caching is not possible. Fat LTO basically works by merging bitcode for all codegen units into a single llvm module and then optimizing. For ThinLTO afaik we already reuses all optimized codegen units which LLVM tells us can be reused:

// If a module exists in both the current and the previous session,
// and has the same LTO cache key in both sessions, then we can re-use it
if prev_key_map.keys.get(module_name) == curr_key_map.keys.get(module_name) {
let work_product = green_modules[module_name].clone();
copy_jobs.push(work_product);
info!(" - {}: re-used", module_name);
assert!(cgcx.incr_comp_session_dir.is_some());
cgcx.cgu_reuse_tracker.set_actual_reuse(module_name, CguReuse::PostLto);
continue;
}

@fenollp
Copy link
Author

fenollp commented Jul 23, 2023

Thanks for your clear and documented answer!

Fat LTO basically works by merging bitcode for all codegen units into a single llvm module and then optimizing.

I see how caching is not possible. Then how about changing how FatLTO is done? Instead of merging+optimizing all in one step, shouldn't we be doing this with various subsets of the crates tree? I'm thinking walking the dependency tree from the bottom up, this way parts of the tree that weren't touched can be identified and reused.

@bjorn3
Copy link
Member

bjorn3 commented Jul 23, 2023

Then how about changing how FatLTO is done? Instead of merging+optimizing all in one step, shouldn't we be doing this with various subsets of the crates tree?

What is the benefit of that over ThinLTO?

this way parts of the tree that weren't touched can be identified and reused.

You can still have optimizations that are affected by parts of the call graph that did change. That is the point of LTO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-enhancement Category: An issue proposing an enhancement or a PR with one. I-compiletime Issue: Problems and improvements with respect to compile times. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants