Skip to content

Commit a44d002

Browse files
committed
add faster sqlite
1 parent 7c6fa10 commit a44d002

File tree

22 files changed

+3486
-96
lines changed

22 files changed

+3486
-96
lines changed

.github/workflows/ci.yml

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ jobs:
3434
- name: Rust Cache dependencies
3535
uses: Swatinem/rust-cache@v2
3636

37-
- name: Clippy --features sqlite,postgresql,mysql,xml
38-
run: cargo clippy --features sqlite,postgresql,mysql,xml --all-targets -- -D warnings
37+
- name: Clippy --features sqlite,postgresql,mysql,xml,sqlitefaster
38+
run: cargo clippy --features sqlite,postgresql,mysql,xml,sqlitefaster --all-targets -- -D warnings
3939

4040
- name: Clippy --features sqlite
4141
run: cargo clippy --features sqlite --all-targets -- -D warnings
4242

43+
- name: Clippy --features sqlitefaster
44+
run: cargo clippy --features sqlitefaster --all-targets -- -D warnings
45+
4346
- name: Clippy --features postgresql
4447
run: cargo clippy --features postgresql --all-targets -- -D warnings
4548

@@ -49,12 +52,15 @@ jobs:
4952
- name: Clippy --features xml
5053
run: cargo clippy --features xml --all-targets -- -D warnings
5154

52-
- name: Clippy --features sqlite,postgresql,mysql,xml,decimal
53-
run: cargo clippy --features sqlite,postgresql,mysql,xml,decimal --all-targets -- -D warnings
55+
- name: Clippy --features sqlite,postgresql,mysql,xml,sqlitefaster,decimal
56+
run: cargo clippy --features sqlite,postgresql,mysql,xml,sqlitefaster,decimal --all-targets -- -D warnings
5457

5558
- name: Clippy --features sqlite,decimal
5659
run: cargo clippy --features sqlite,decimal --all-targets -- -D warnings
5760

61+
- name: Clippy --features sqlitefaster,decimal
62+
run: cargo clippy --features sqlitefaster,decimal --all-targets -- -D warnings
63+
5864
- name: Clippy --features postgresql,decimal
5965
run: cargo clippy --features postgresql,decimal --all-targets -- -D warnings
6066

@@ -134,6 +140,43 @@ jobs:
134140
cargo test --doc --features sqlite,decimal
135141
136142
143+
test_sqlitefaster:
144+
name: Test SQLiteFaster
145+
needs: [lint]
146+
runs-on: ${{ matrix.os }}
147+
strategy:
148+
matrix:
149+
os:
150+
- ubuntu-latest
151+
- macos-latest
152+
- windows-latest
153+
154+
steps:
155+
- uses: actions/checkout@v4
156+
157+
- name: Rust Cache dependencies
158+
uses: Swatinem/rust-cache@v2
159+
160+
- name: Install latest nextest release
161+
uses: taiki-e/install-action@nextest
162+
163+
- name: Check Schema
164+
run: cargo check --features sqlitefaster --all-targets
165+
env:
166+
DATABASE_URL: "file:/tests/db/sqlite/complex_sample.gnucash"
167+
168+
- name: Run tests --features sqlitefaster
169+
run: cargo nextest run --config-file ${{ github.workspace }}/.github/nextest.toml --profile ci --features sqlitefaster
170+
171+
- name: Run tests --features sqlitefaster,decimal
172+
run: cargo nextest run --config-file ${{ github.workspace }}/.github/nextest.toml --profile ci --features sqlitefaster,decimal
173+
174+
- name: Run doc tests
175+
run: |
176+
cargo test --doc --features sqlitefaster
177+
cargo test --doc --features sqlitefaster,decimal
178+
179+
137180
test_mysql:
138181
name: Test MySQL
139182
needs: [lint]
@@ -238,4 +281,4 @@ jobs:
238281
- name: Run doc tests
239282
run: |
240283
cargo test --doc --features postgresql
241-
cargo test --doc --features postgresql,decimal
284+
cargo test --doc --features postgresql,decimal

Cargo.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ flate2 = "1.0"
2727
tokio = { version = "1.36", features = ["sync"] }
2828
num-traits = "0.2"
2929
thiserror = "1.0"
30+
rusqlite = { version = "*", features = ["bundled", "chrono"], optional = true }
3031

3132
[lib]
3233
name = "rucash"
@@ -48,6 +49,7 @@ sqlx_common = [
4849
"sqlx/chrono",
4950
]
5051
sqlite = ["sqlx_common", "sqlx/sqlite"]
52+
sqlitefaster = ["rusqlite"]
5153
postgresql = ["sqlx_common", "sqlx/postgres"]
5254
mysql = ["sqlx_common", "sqlx/mysql"]
5355
xml = ["xmltree"]
@@ -56,13 +58,18 @@ decimal = ["rust_decimal"]
5658
[[bench]]
5759
name = "benchmark"
5860
harness = false
59-
required-features = ["sqlite", "xml"]
61+
required-features = ["sqlite", "xml", "sqlitefaster"]
6062

6163
[[test]]
6264
name = "sqlite"
6365
path = "tests/sqlite.rs"
6466
required-features = ["sqlite"]
6567

68+
[[test]]
69+
name = "sqlitefaster"
70+
path = "tests/sqlitefaster.rs"
71+
required-features = ["sqlitefaster"]
72+
6673
[[test]]
6774
name = "mysql"
6875
path = "tests/mysql.rs"
@@ -81,4 +88,4 @@ required-features = ["postgresql"]
8188
[[test]]
8289
name = "all"
8390
path = "tests/all.rs"
84-
required-features = ["sqlite", "postgresql", "mysql", "xml"]
91+
required-features = ["sqlite", "postgresql", "mysql", "xml", "sqlitefaster"]

benches/benchmark.rs

Lines changed: 117 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,117 @@
1-
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2-
3-
fn uri_sqlite() -> String {
4-
format!(
5-
"sqlite://{}/tests/db/sqlite/complex_sample.gnucash?mode=ro",
6-
env!("CARGO_MANIFEST_DIR")
7-
)
8-
}
9-
10-
fn uri_xml() -> String {
11-
format!(
12-
"{}/tests/db/xml/complex_sample.gnucash",
13-
env!("CARGO_MANIFEST_DIR")
14-
)
15-
}
16-
17-
fn benchmark_sql_query(c: &mut Criterion) {
18-
let rt = tokio::runtime::Runtime::new().unwrap();
19-
let book = rt.block_on(async {
20-
let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap();
21-
rucash::Book::new(query).await.unwrap()
22-
});
23-
24-
c.bench_function("sql query", |b| {
25-
b.to_async(&rt).iter(|| async {
26-
book.accounts_contains_name_ignore_case(black_box("aS"))
27-
.await
28-
});
29-
});
30-
}
31-
32-
fn benchmark_vec_filter(c: &mut Criterion) {
33-
let rt = tokio::runtime::Runtime::new().unwrap();
34-
let book = rt.block_on(async {
35-
let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap();
36-
rucash::Book::new(query).await.unwrap()
37-
});
38-
39-
c.bench_function("vec filter", |b| {
40-
b.to_async(&rt).iter(|| async {
41-
let vec = book.accounts().await.unwrap();
42-
let _: Vec<_> = vec
43-
.into_iter()
44-
.filter(|x| x.name.to_lowercase().contains(black_box("aS")))
45-
.collect();
46-
})
47-
});
48-
}
49-
50-
fn benchmark_xml_book(c: &mut Criterion) {
51-
let rt = tokio::runtime::Runtime::new().unwrap();
52-
let book = rt.block_on(async {
53-
let query = rucash::XMLQuery::new(&uri_xml()).unwrap();
54-
rucash::Book::new(query).await.unwrap()
55-
});
56-
57-
c.bench_function("XMLBook", |b| {
58-
b.to_async(&rt).iter(|| async { book.accounts().await })
59-
});
60-
}
61-
62-
fn benchmark_sqlite_book(c: &mut Criterion) {
63-
let rt = tokio::runtime::Runtime::new().unwrap();
64-
let book = rt.block_on(async {
65-
let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap();
66-
rucash::Book::new(query).await.unwrap()
67-
});
68-
69-
c.bench_function("SqliteBook", |b| {
70-
b.to_async(&rt).iter(|| async { book.accounts().await })
71-
});
72-
}
73-
74-
criterion_group!(
75-
benches,
76-
benchmark_sql_query,
77-
benchmark_vec_filter,
78-
benchmark_xml_book,
79-
benchmark_sqlite_book,
80-
);
81-
criterion_main!(benches);
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
3+
fn uri_sqlite() -> String {
4+
format!(
5+
"sqlite://{}/tests/db/sqlite/complex_sample.gnucash?mode=ro",
6+
env!("CARGO_MANIFEST_DIR")
7+
)
8+
}
9+
10+
fn uri_xml() -> String {
11+
format!(
12+
"{}/tests/db/xml/complex_sample.gnucash",
13+
env!("CARGO_MANIFEST_DIR")
14+
)
15+
}
16+
17+
fn uri_sqlitefaster() -> String {
18+
format!(
19+
"file:/{}/tests/db/sqlite/complex_sample.gnucash",
20+
env!("CARGO_MANIFEST_DIR")
21+
)
22+
}
23+
24+
fn benchmark_sql_query(c: &mut Criterion) {
25+
let rt = tokio::runtime::Runtime::new().unwrap();
26+
let book = rt.block_on(async {
27+
let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap();
28+
rucash::Book::new(query).await.unwrap()
29+
});
30+
31+
c.bench_function("sql query", |b| {
32+
b.to_async(&rt).iter(|| async {
33+
book.accounts_contains_name_ignore_case(black_box("aS"))
34+
.await
35+
});
36+
});
37+
}
38+
39+
fn benchmark_sql_faster_query(c: &mut Criterion) {
40+
let rt = tokio::runtime::Runtime::new().unwrap();
41+
let book = rt.block_on(async {
42+
let query = rucash::SQLiteQueryFaster::new(&uri_sqlitefaster()).unwrap();
43+
rucash::Book::new(query).await.unwrap()
44+
});
45+
46+
c.bench_function("sql faster query", |b| {
47+
b.to_async(&rt).iter(|| async {
48+
book.accounts_contains_name_ignore_case(black_box("aS"))
49+
.await
50+
});
51+
});
52+
}
53+
54+
fn benchmark_vec_filter(c: &mut Criterion) {
55+
let rt = tokio::runtime::Runtime::new().unwrap();
56+
let book = rt.block_on(async {
57+
let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap();
58+
rucash::Book::new(query).await.unwrap()
59+
});
60+
61+
c.bench_function("vec filter", |b| {
62+
b.to_async(&rt).iter(|| async {
63+
let vec = book.accounts().await.unwrap();
64+
let _: Vec<_> = vec
65+
.into_iter()
66+
.filter(|x| x.name.to_lowercase().contains(black_box("aS")))
67+
.collect();
68+
})
69+
});
70+
}
71+
72+
fn benchmark_xml_book(c: &mut Criterion) {
73+
let rt = tokio::runtime::Runtime::new().unwrap();
74+
let book = rt.block_on(async {
75+
let query = rucash::XMLQuery::new(&uri_xml()).unwrap();
76+
rucash::Book::new(query).await.unwrap()
77+
});
78+
79+
c.bench_function("XMLBook", |b| {
80+
b.to_async(&rt).iter(|| async { book.accounts().await })
81+
});
82+
}
83+
84+
fn benchmark_sqlite_book(c: &mut Criterion) {
85+
let rt = tokio::runtime::Runtime::new().unwrap();
86+
let book = rt.block_on(async {
87+
let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap();
88+
rucash::Book::new(query).await.unwrap()
89+
});
90+
91+
c.bench_function("SqliteBook", |b| {
92+
b.to_async(&rt).iter(|| async { book.accounts().await })
93+
});
94+
}
95+
96+
fn benchmark_sqlitefaster_book(c: &mut Criterion) {
97+
let rt = tokio::runtime::Runtime::new().unwrap();
98+
let book = rt.block_on(async {
99+
let query = rucash::SQLiteQueryFaster::new(&uri_sqlitefaster()).unwrap();
100+
rucash::Book::new(query).await.unwrap()
101+
});
102+
103+
c.bench_function("SqliteFasterBook", |b| {
104+
b.to_async(&rt).iter(|| async { book.accounts().await })
105+
});
106+
}
107+
108+
criterion_group!(
109+
benches,
110+
benchmark_sql_query,
111+
benchmark_sql_faster_query,
112+
benchmark_vec_filter,
113+
benchmark_xml_book,
114+
benchmark_sqlite_book,
115+
benchmark_sqlitefaster_book,
116+
);
117+
criterion_main!(benches);

makefile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@ all: test build
22
build:
33
cargo build
44
test:
5-
cargo test --features sqlite,postgresql,mysql,xml
5+
cargo test --features sqlite,postgresql,mysql,xml,sqlitefaster
66
cargo test --features sqlite
7+
cargo test --features sqlitefaster
78
cargo test --features postgresql
89
cargo test --features mysql
910
cargo test --features xml
10-
cargo test --features sqlite,postgresql,mysql,xml,decimal
11+
cargo test --features sqlite,postgresql,mysql,xml,sqlitefaster,decimal
1112
cargo test --features sqlite,decimal
13+
cargo test --features sqlitefaster,decimal
1214
cargo test --features postgresql,decimal
1315
cargo test --features mysql,decimal
1416
cargo test --features xml,decimal
1517
clean:
1618
cargo clean
1719
bench:
18-
cargo bench --features sqlite,xml
20+
cargo bench --features sqlite,xml,sqlitefaster
1921
check:
20-
cargo check --features sqlite,postgresql,mysql,xml --all-targets
21-
cargo clippy --features sqlite,postgresql,mysql,xml --all-targets
22-
cargo check --features sqlite,postgresql,mysql,xml,decimal --all-targets
23-
cargo clippy --features sqlite,postgresql,mysql,xml,decimal --all-targets
22+
cargo check --features sqlite,postgresql,mysql,xml,sqlitefaster --all-targets
23+
cargo clippy --features sqlite,postgresql,mysql,xml,sqlitefaster --all-targets
24+
cargo check --features sqlite,postgresql,mysql,xml,sqlitefaster,decimal --all-targets
25+
cargo clippy --features sqlite,postgresql,mysql,xml,sqlitefaster,decimal --all-targets
2426
checkschema:
2527
export DATABASE_URL=sqlite://tests/db/sqlite/complex_sample.gnucash?mode=ro
2628
cargo check --features sqlite,schema --all-targets

0 commit comments

Comments
 (0)