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

sqlx prepare should not clean sqlx #2785

Open
cycraig opened this issue Sep 27, 2023 · 6 comments
Open

sqlx prepare should not clean sqlx #2785

cycraig opened this issue Sep 27, 2023 · 6 comments
Labels

Comments

@cycraig
Copy link
Contributor

cycraig commented Sep 27, 2023

Bug Description

The minimal_project_recompile step of cargo sqlx prepare --workspace always runs cargo clean -p sqlx, because it depends on sqlx-macros (assuming the macros feature is enabled).

cargo sqlx prepare --database-url "postgres://postgres:password@localhost/example" --workspace
    Cleaning [=============================] 1/1: sqlx, 0 files/folders cleaned 

Surprisingly, cargo clean -p sqlx can take several minutes in a large project, and I don't think it is necessary since sqlx itself does not contain any query macros.

Edit: it seems like it was always the plan to exclude sqlx from being cleaned: #1802 (comment)

Suggestions

  • Hardcode an exclusion filter for sqlx in out_of_workspace_dependents.
  • Accept a list of exclusions from an environment variable, like SQLX_PREPARE_NO_CLEAN="sqlx crate1 crate2"?
  • Something else?

Minimal Reproduction

Reproducible in any workspace where the macros feature is enabled for sqlx::query!, and cargo sqlx prepare --workspace is run.

E.g. https://github.com/cycraig/sqlx_prepare_bug.

Info

  • SQLx version: 0.7.1
  • SQLx features enabled: ["chrono", "ipnetwork", "json", "macros", "migrate", "postgres", "runtime-tokio-rustls", "uuid"] (only macros seems relevant here)
  • Database server and version: Postgres 14
  • Operating system: MacOS
  • rustc --version: 1.72.0
@CosmicHorrorDev
Copy link
Contributor

Edit: it seems like it was always the plan to exclude sqlx from being cleaned: #1802 (comment)

It looks like this issue is now of interest to me. I can take a look, but yes excluding sqlx from the clean should be fine

@mplanchard
Copy link

mplanchard commented Mar 19, 2024

Just noting that for our relatively large workspace, cargo sqlx prepare has gone from being a fairly quick operation to one that takes nearly 4 minutes to complete:

❯ time make db-sqlx-offline-data
Checking cargo sqlx-cli version
cargo sqlx-cli (0.7.3) is the same version as sqlx-cli (0.7.3)
Generating sqlx offline data
     Removed 13 files, 334.6KiB total
    Checking sqlx v0.7.3
   <snip>
    Finished dev [unoptimized + debuginfo] target(s) in 14.81s
query data written to .sqlx in the workspace root; please check this into version control

________________________________________________________
Executed in  230.85 secs    fish           external
   usr time  248.45 secs  397.00 micros  248.45 secs
   sys time   43.08 secs  196.00 micros   43.08 secs

The make command just runs:

	cargo sqlx prepare \
		--workspace --database-url "$$DATABASE_URL" \
		-- --all-features --all-targets

@CosmicHorrorDev
Copy link
Contributor

Do you have a fairly large target dir (as in 10's of GBs)?

@mplanchard
Copy link

Yep, it's quite large:

❯ du -sh target
83G     target

@CosmicHorrorDev
Copy link
Contributor

CosmicHorrorDev commented Mar 19, 2024

Cleaning that will likely drastically reduce the run time as a temporary workaround

I've been meaning to dig into cargo clean -p more to see what all is slow there, but I've had very limited free time lately

@mplanchard
Copy link

Cleaning that will likely drastically reduce the run time as a temporary workaround

Oh yeah, nice! Did an rm -rf target, recompiled, and now it's much faster indeed:

❯ du -sh target
2.2G    target

❯ time make db-sqlx-offline-data
Checking cargo sqlx-cli version
cargo sqlx-cli (0.7.3) is the same version as sqlx-cli (0.7.3)
Generating sqlx offline data
     Removed 0 files
    Checking sqlx v0.7.3
    <snip>
    Finished dev [unoptimized + debuginfo] target(s) in 6.85s
query data written to .sqlx in the workspace root; please check this into version control
________________________________________________________
Executed in   12.95 secs    fish           external
   usr time   20.38 secs    0.00 millis   20.38 secs
   sys time    8.51 secs    1.01 millis    8.51 secs

Thanks for the tip!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants