Skip to content

Commit

Permalink
Merge pull request #4338 from c410-f3r/master
Browse files Browse the repository at this point in the history
Update `wtx`
  • Loading branch information
weiznich authored Nov 10, 2024
2 parents a5f7548 + d78c1c9 commit 2090344
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
9 changes: 1 addition & 8 deletions diesel_bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@ futures-util = { version = "0.3", optional = true }
diesel-async = { version = "0.5.0", optional = true, default-features = false }
criterion-perf-events = { version = "0.4", optional = true }
perfcnt = { version = "0.8", optional = true }
wtx = { default-features = false, features = [
"atoi",
"memchr",
"postgres",
"simdutf8",
"std",
"tokio",
], optional = true, version = "0.14" }
wtx = { default-features = false, features = ["optimization", "postgres", "std", "tokio"], optional = true, version = "0.23" }

[dependencies.diesel]
path = "../diesel"
Expand Down
24 changes: 13 additions & 11 deletions diesel_bench/benches/wtx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use wtx::{
client::postgres::{Config, Executor, ExecutorBuffer},
Executor as _, Record as _,
},
misc::{Either, UriRef},
rng::StdRng,
misc::{simple_seed, Either, IterWrapper, UriRef, Xorshift64},
};

pub struct Comment {
Expand Down Expand Up @@ -92,7 +91,7 @@ pub fn bench_loading_associations_sequentially(b: &mut Bencher) {
let mut posts = Vec::with_capacity(LEN);
conn.fetch_many_with_stmt(
posts_query.as_str(),
&mut users.iter().map(|user| user.id),
IterWrapper(users.iter().map(|user| user.id)),
|record| {
posts.push(Post {
body: record.decode_opt(3).unwrap(),
Expand All @@ -116,7 +115,7 @@ pub fn bench_loading_associations_sequentially(b: &mut Bencher) {
let mut comments = Vec::with_capacity(LEN);
conn.fetch_many_with_stmt(
comments_query.as_str(),
&mut posts.iter().map(|post| post.id),
IterWrapper(posts.iter().map(|post| post.id)),
|record| {
comments.push(Comment {
id: record.decode(0).unwrap(),
Expand Down Expand Up @@ -259,10 +258,10 @@ async fn connection() -> Executor<wtx::Error, ExecutorBuffer, TcpStream> {
.or_else(|_| dotenvy::var("DATABASE_URL"))
.expect("DATABASE_URL must be set in order to run tests");
let uri = UriRef::new(url.as_str());
let mut rng = StdRng::default();
let mut rng = Xorshift64::from(simple_seed());
let mut conn = Executor::connect(
&Config::from_uri(&uri).unwrap(),
ExecutorBuffer::with_default_params(&mut rng),
ExecutorBuffer::with_capacity((512, 8192, 512, 32), 32, &mut rng).unwrap(),
&mut rng,
TcpStream::connect(uri.host()).await.unwrap(),
)
Expand Down Expand Up @@ -315,9 +314,12 @@ async fn insert_posts<const N: usize>(conn: &mut Executor<wtx::Error, ExecutorBu
},
);

conn.execute_with_stmt(insert_stmt.as_str(), &mut params.into_iter().flatten())
.await
.unwrap();
conn.execute_with_stmt(
insert_stmt.as_str(),
IterWrapper(params.into_iter().flatten()),
)
.await
.unwrap();
}

async fn insert_users<const N: usize>(
Expand All @@ -331,14 +333,14 @@ async fn insert_users<const N: usize>(
.unwrap();
});

let mut params = (0..N).into_iter().flat_map(|idx| {
let params = (0..N).into_iter().flat_map(|idx| {
[
Either::Left(format!("User {idx}")),
Either::Right(hair_color_init(idx)),
]
});

conn.execute_with_stmt(query.as_str(), &mut params)
conn.execute_with_stmt(query.as_str(), IterWrapper(params))
.await
.unwrap();
}

0 comments on commit 2090344

Please sign in to comment.