Repository navigation
refactor: Keep parsed sqlx-data.json in a cache instead of reparsing - #1684
Conversation
|
You may also be interested in the discussion in #1598, and in particular, #1598 (comment) |
|
I dove into the rabbit hole for a bit and it seems like there is a lot of discussion on restructuring how query information is returned from the database and potentially stored. The one-file-per-query implementation would mitigate the same issue this PR addresses, and keeping a cached pool for communicating with the DB is a similar approach to what is done with this PR (I was just looking into that today since I noticed each query opens a new connection. This makes running Having looked into the discussion more, I'm really not sure where this PR stands. It seems to be an improvement to the current offline workflow, but that may be changing drastically |
|
I think this PR still has merit because we'll probably put out another point release or two before 0.6.0, especially since we have so many PRs in the pipeline. |
I didn't delve too much into how things are used, but from what I can tell when using the offline data cache each compile-time verified query will parse the entire
sqlx-data.jsonfile. This change switches to caching the parsedsqlx-data.jsonfiles in a two-layer cache where the first layer is keyed by the path tosqlx-data.json(since there can be multiple) and the second layer is keyed by the query hash.This did involve changing some of the types returned for errors since this now uses
Strings instead ofserde::de::Err::custom. I didn't think this was a huge issue since the error type is aBox<dyn std::error::Error>.Comparison
Note: the numbers here are ballpark around what I see at work. We have a workspace with over 200 queries that uses
--mergedto create a workspace levelsqlx-data.jsonfile. This file ends up being a hair over 500 KiBSetup
Cargo.tomlmain.rsis generated with a python file calledgen_main.pyI used 200 queries for this test so
./gen_main.py 200 > main.rsmakes the main. Here's an example of./gen_main.py 1and then here is the table for the sqlite database, just created on the command line with
$ sqlite3 repro.dbRunning
With all the setup out of the way here are some of the numbers. Both of the check times are from
$ hyperfine --warmup 1 --prepare 'touch src/main.rs' 'cargo check'sqlx-data.jsonsize: 305 KiBcargo checkonmaster:(mean ± σ): 6.298 s ± 0.035 scargo checkon this branch:(mean ± σ): 574.8 ms ± 3.5 ms