-
Notifications
You must be signed in to change notification settings - Fork 1.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
Every sqlx::query!() call adds 80+ milliseconds to build time #1096
Comments
I added some print statements to the expand_query() proc_macro to measure the time taken by macro expansion. All 87 queries which use expand_query() in my latest revision only take 0.8 seconds (wall clock) in total. The wall clock time between the first macro expansion and the last one is 1.1 seconds. |
#941 should help with compile times, but I'm not sure when I'm going to get back to it. |
#941 might shave some time off the 1.1 seconds taken by the query! macro expansion, but that's about it right? The majority of the time is spent by the Rust compiler compiling the generated code I guess? |
Oh, I see. There is the Otherwise incremental re-linking could help I guess, though I don't know much about that. |
I tried running "cargo +nightly rustc -- -Z self-profile" followed by "summarize summarize *.mm_profdata", which produces the following profile results:
57% of the time is spent in the linker. Another 19.5% (1.33 seconds) is spent expanding macros, which is close to the time I measured earlier. I tried using cranelift, but it panics during the build. Interestingly, the nightly compiler is much faster than rustc 1.50.0. A build takes just 7 seconds instead of 12 seconds! |
Following the advice of jplatte, I also tried using lld. I create the file ~/.cargo/config, with the following contents:
This improves the compile time to 8.5 seconds on Rust 1.50.0 (instead of 12 seconds), and just 3.5 seconds on nightly (instead of 7 seconds). Nice! |
We've made some improvements to compile times when using |
I've been developing an application over the last couple of months, using sqlx. I'm very happy with it, but the debug build times of my application seemed to increase steadily over time. I'm using sqlx 0.4.2, Rust 1.50, and a Postgres 12 database.
I'm pretty sure it's due to compiling the sqlx::query!() calls. I wrote a small script which checks out each source code revision, and measures the 'cargo build' time. (It resets the database, compiles the code, appends something trivial to my main.rs, and then compiles the code again. The measured time is the time taken by the last compilation). The same script also counts the number of occurrences of 'sqlx::query' in my code. The measurements are made on a AMD Ryzen 5900X CPU. This is the result:
When I started using sqlx, the 'cargo build' time was 5 seconds. Now it's around 12 seconds. During that time I wrote 92 queries. Every time I add a bunch of queries to the code, the time taken by 'cargo build' goes up by a similar amount. In my case, around 88 milliseconds per sqlx::query!().
Using offline mode does not seem to make any difference.
I also looked at the total LOC and the number of 'async fn' occurrences of each revision. These also have some correlation with the compile times of course, but it's not nearly as strong as the correlation with the number of sqlx::query!() calls.
I'm worried that compile times will keep on going up in the future, because I expect to be writing a lot more queries. Is there anything I can do to decrease the time taken to compile each query, besides trying to split my code up into lots of little crates?
The text was updated successfully, but these errors were encountered: