-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 a cached DB connection instead of always recreating for sqlx-macros
#1782
Reuse a cached DB connection instead of always recreating for sqlx-macros
#1782
Conversation
Also something that should be covered. A side-effect of this change is that the single db connection is never actually dropped (since lazy statics aren't dropped when the program finishes). This means that, for instance, if you are using SQLite there will be a lingering set of I'm not sure the best way to handle this. The lazy staatic could be consumed if |
It shouldn't create any temporary files if you disable journaling by doing We should also probably set the connection to read-only mode but I'm wondering if that will cause |
Thanks for the insight! Disabling journaling for SQLite did fix the lingering write-ahead-log and shared-memory files. I also tried setting I think my final lingering question is with handling features when using the
This is because |
Since I didn't write the I think instead we can make the |
Trying that out ends up running into more errors
I opted for moving all the stuff within |
Worth noting that I forgot my personal laptop was using rust 1.59 when I was running the local SQLite benchmarks in my initial description which had incremental compilation disabled. Rerunning them on 1.60 gets a reduction in The other timings were using nightly, so the same discrepancy wasn't present |
I think because this basically makes the |
Noticed there was a simple merge conflict, so just pushed to resolve it |
Similar spirit to #1684, but this focus in on speeding up
cargo sqlx prepare
with a remote database. This change reuses the same DB connection instead of recreating one for eachsqlx-macros
query macro.Comparison
Three setups tested here. Two MariaDB setups on my work computer, one local and one remote, and the SQLite setup from #1684 on my personal laptop
MariaDB query #: 332
MariaDB
sqlx-data.json
size: 705 KiBSQLite query #: 200
SQLite
sqlx-data.json
size: 305 KiBThe runtimes for
cargo sqlx prepare
on the various setupsmaster
(f858138)(new - old) / old
It looks like the change lowered
cargo sqlx prepare
times across the board with the most significant impact by far on remote DBs