-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Building project takes a *long* time (esp compilation time for datafusion
core crate)
#13814
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
Comments
install sccache and tell rust to use it
With the above two options I see a full build on my machine taking 100.8s (1m 40.8s). https://corrode.dev/blog/tips-for-faster-rust-compile-times/ |
This makes sense -- thank you @Omega359 However, I think it will not help CI where the use of such caching doesn't help (and since the intermediate rust files are so large trying to use cargo cache wasn't effective in the past when we tried) I would love to figure out how to break the datafusion core crate into smaller pieces / crates that can be compiled in parallel |
fwiw I tried to gather a bit more info with llvm-lines:
|
yes! and move around sqlparser dependency when doing so :) |
FWIW the only reliable mechanism I've found to measure this is to comment out modules and measure the impact on compilation time. Llvm-lines and cargo-bloat can be informative, but not all lines are created equal. This is especially true for code with complex lifetimes and/or async. Anything making extensive use of macros is likely a good place to start |
might be compiler related? |
IIRC that relates to type checking expressions, and therefore this would suggest the compiler is spending a lot of time resolving generics. At least historically non-boxed async has been a good source of this, as async "desugars" to quite complex generic code, and often has quite complex Send / lifetime constraints. Edit: rust-lang/rust#87012 is the related issue I was thinking of |
Thanks @tustvold it was nice attempt to solve it 3 years ago, hopefully someone is planning to close it out one day |
One thing that is strange is that we have moved most of the code out of datafusion-core now. I am still hoping we can get https://github.com/apache/datafusion/tree/main/datafusion/core/src/datasource/physical_plan out of the core somehow (I know @AdamGS is thinking about that) However, I don't think that is the problem either as all the formts are feature gated and when I build with no default feaatures When I build with no default features: cargo build --timings -p datafusion --no-default-features I get And then adding parquet (by far the largest / most complex), it goes up by only 1 seconds cargo build --timings -p datafusion --no-default-features --features=parquet |
I also tried removing all the doctests from lib.rs and that didn't help (I didn't expect it to but I wanted to try) diff --git a/datafusion/core/src/lib.rs b/datafusion/core/src/lib.rs
index b4d5f9740..9e1f9795e 100644
--- a/datafusion/core/src/lib.rs
+++ b/datafusion/core/src/lib.rs
@@ -824,282 +824,3 @@ pub mod test;
mod schema_equivalence;
pub mod test_util;
-
-#[cfg(doctest)]
-doc_comment::doctest!("../../../README.md", readme_example_test);
-
-// Instructions for Documentation Examples |
I also tried cutting out (ablating) the contents of b/datafusion/core/src/physical_planner.rs but that diidn't seem to make any difference either |
using following command on release 42.0.0, 45.0.0, and current main. cargo build -p datafusion-cli --timings -j 10 There is some improvement in build time (201sec -> 190 sec-->183sec), for datafusion crate(65->65->49).(some progress!!) also, this article and the issue mentioned above by @tustvold(rust-lang/rust#87012) looks promising. The problem cause also seems to be similar between evaluate_obligation[1] and [1]: I think evaluate_obligation and process_obligation are same, correct me if I am wrong. |
Pulling stuff out of core helped! Thank you ! I was wondering recently if the the probably could be related to all the re-exports ( I think before we spend a lot of time engineering some solution we should try and do something quick and dirty to prove it will help. If it does then we can figure out how to make it work reasonably / get it in chunks |
it might be good idea for reasons other than compilation time. |
New Rust compiler has notable performance changes, https://nnethercote.github.io/2025/03/19/how-to-speed-up-the-rust-compiler-in-march-2025.html looking fwd |
I ran some profiling recently and it seems like catalog is also getting pretty long to compile (this is before #15459) |
I wonder since catalog is a smaller crate, we could more easily figure out what was taking time to compile... |
I did some profiling. RUSTC_BOOTSTRAP=1 cargo rustc -p datafusion-catalog -- -Z self-profile -Z self-profile-events=default,args culprits are some asynchronous functions(Memtable::{scan, insert_into}, StreamTable::{scan, insert_into} StreamTableFactory::create, StreamWrite::write_all, ViewTable::scan ):- Each of them taking 1-2 sec(5-10% of total time) in analysis phase only. there are a couple hundred evaluate_obligation call under each type_check of pattern This does not happen with other asynchronous method eg. |
A break in the case! 🕵 |
Thanks @logan-keede btw is it a release build? can you also check with LTO and non LTO, sometimes this link optimizations takes time as well UPD: What rustc version used? |
It is debug build, I will try to check it with LTO and non LTO sometime soon. rustc version:- 1.84.1 |
1.86 introduced some compilation improvements https://releases.rs/docs/1.86.0/#internal-changes |
It seems like 1.86 won't be released for 3 more days: https://releases.rs/docs/1.86.0/ It would be cool to update and try it |
rust-lang/rust#87012 (comment) This thread mentioned a similar issue to what we have. #13814 (comment) has the conclusion already 😆 |
still good to get a heads up |
Is it possible to change |
changing to release build lto or non-lto did not make much of a difference from debug build except the extra process that seems to be taking some time. changing to rustc 1.86 did reduce the build time from 18sec -> 14 sec and then to 12 sec when I made |
Originally posted by @alamb in #15625 (comment) It actually does not seem to have much impact on CI. TLDR: Improvements I observed were actually introduced in 1.85 and we were already benefiting from them. Sorry for the false positive. |
Interesting material comes up this week UPD: These guys proposing something we already started, namely split large modules into smaller ones which allows compile parallelization |
Interesting! Though that is via codegen (they are code gening rust so can make thousands of modules) I also found it fascainting they use DataFusion too! 🐶 😎 |
Is your feature request related to a problem or challenge?
Compiling the datafusion crate currently takes 40 seconds on my machine, far longer than any other crate
This slows down CI builds as well as my own local development workflow
For example, running
# start from clean checking rm -rf target cargo build --timings
Generates a chart as follows (attached here): carg-timings.zip
Describe the solution you'd like
I would like to speed up compilation somehow -- likely by decreasing the time required for datafusion-core
Describe alternatives you've considered
I think the first thing would be to figure out if possible what is taking up so much time when building the core crate
I suspect it has to do with listing table / some of the various file format support, but I don't have data to justify that
Additional context
No response
The text was updated successfully, but these errors were encountered: