avinassh / avinassh/fast-sqlite3-inserts

`basic_async` not actually asynchronous ?

Open
#22 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
410
Forks
42
PR merge metrics
No merged PRs in 30d

Description

I might be missing something here as I'm still new to async in rust, but as I understand it calling await on a future forces the runtime to serialize the execution of the program, this means that this code:

```rust
conn.execute("PRAGMA cache_size = 1000000;").await?;
conn.execute("PRAGMA locking_mode = EXCLUSIVE;").await?;
conn.execute("PRAGMA temp_store = MEMORY;").await?;
```
is completely synchronized and each call to the database needs to complete before the next call starts.
Now, this seems fine as this only happens once outside of the benchmark loop.

But all the code in the `faker` function also uses await on each async call.
For example this code :
```rust
let stmt_with_area = tx
.prepare("INSERT INTO user VALUES (NULL, ?, ?, ?)")
.await?;
let stmt = tx
.prepare("INSERT INTO user VALUES (NULL, NULL, ?, ?)")
.await?;
```

It seems to me that there is no reason the needs to be serialized and we should join these calls, in something like:
```rust
let (stmt_with_area, stmt ) = tokio::join!(
tx.prepare("INSERT INTO user VALUES (NULL, ?, ?, ?)"),
tx.prepare("INSERT INTO user VALUES (NULL, NULL, ?, ?)")
)
```

Finally, it also seems that we don't actually need to await the execution of the statements themselves inside the `for`
but that would require saving all the futures in a big vector and then joining them, which seems a bit odd and would consume a lot of memory when running the for loop for 10e6 iterations.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.