Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions BENCHMARK.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ If the file is absent, the built-in defaults are used, so `cargo bench --bench b
| `dataset.blocks` | `32` | Local-chain entries per changeset. |
| `dataset.scripts_per_transaction` | `8` | Cached scripts per descriptor per transaction. |
| `dataset.locked_outpoints` | `8` | Locked outpoints per changeset. |
| `turso.multiprocess_wal` | `true` | Open Turso with its opt-in multi-process WAL mode. |
| `backends.turso`, `backends.sqlite`, `backends.redb` | `true` | Backends included in the run; at least one must be enabled. |

All settings are optional and unknown keys are rejected. The suite fails with an actionable error when a value is zero, `writers` is empty or contains zero, or no backend is enabled.
Expand All @@ -56,7 +55,7 @@ All settings are optional and unknown keys are rejected. The suite fails with an
- Every backend receives the same generated `bdk_wallet::ChangeSet` values. By default, each changeset contains 16 transactions, 32 local-chain entries, 128 cached scripts per descriptor, 8 locked outpoints, both descriptors, and the network.
- Databases are file-backed in a temporary directory, so measurements include persistence and filesystem behavior. The same workload runs on each backend in the same process, one backend at a time.
- The async backends (`bdk_turso` and `bdk_sqlite`) are driven by a Tokio multi-thread runtime whose worker pool is sized to the largest configured writer count (8 by default). `bdk_redb` is synchronous and concurrent writers use operating-system threads.
- `bdk_turso` is opened with `Options::new().with_multiprocess_wal()`, its opt-in multi-process WAL mode, and each concurrent writer opens its own database handle on the same file. All other experimental Turso options are disabled. This is controlled by `turso.multiprocess_wal` in the configuration. `bdk_sqlite` and `bdk_redb` use their default constructors.
- `bdk_turso` is opened with `Options::new()`; the default transaction behavior enables multi-process WAL automatically. Each concurrent writer opens its own database handle on the same file. `bdk_sqlite` and `bdk_redb` use their default constructors.
- Changeset write and read timings reuse one changeset after a warmup phase. The database therefore reaches a steady size and later samples measure repeated updates rather than unbounded growth.
- Concurrent writes start all writers from a barrier and give each writer a distinct changeset. Reported latency is per write; throughput is the number of writers divided by the median round time.
- `bdk_turso` connections wait up to five seconds for a contended write lock before returning an error. `bdk_sqlite` uses its SQLx busy timeout, also five seconds by default. `bdk_redb` blocks when another write transaction is active.
Expand Down Expand Up @@ -107,7 +106,7 @@ Generated on 2026-11-13T15:21:24Z with 5 samples and 1 warmup sample (quick mode
| bdk_redb | 0.2.0 |
| bdk_sqlite | 0.6.0 |
| bdk_turso | 0.3.0 |
| bdk_turso options | multiprocess WAL enabled; other experimental options disabled |
| bdk_turso options | default transaction behavior; multi-process WAL enabled automatically |
| bdk_wallet | 3.2.0 |
| redb (bdk_redb) | 2.6.3 |
| sqlx (bdk_sqlite) | 0.8.6 |
Expand Down Expand Up @@ -148,7 +147,7 @@ Dataset: 64 distinct wallet changesets (16 transactions each).

#### Workload definition

- bdk_turso is opened with `Options::new().with_multiprocess_wal()`; all other experimental options are disabled. Each Turso concurrent writer opens its own database handle on the same file. The other backends use their default constructors.
- bdk_turso is opened with `Options::new()`; the default transaction behavior enables multi-process WAL automatically. Each Turso concurrent writer opens its own database handle on the same file. The other backends use their default constructors.
- Each changeset contains 16 transactions, 32 local-chain entries, 128 cached scripts per descriptor, and 8 locked outpoints, plus both descriptors and the network.
- Write and read measurements reuse the same changeset, so the database stops growing after the warmup phase and later samples measure steady-state updates.
- Concurrent write rounds start all writers from a barrier and persist one distinct changeset per writer. Reported latency is per write; throughput is writers divided by the median round time.
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ Notable changes to `bdk_turso` are documented here. Released versions are linked

## [Unreleased]

### Added

- `Options::with_busy_timeout` sets how long a connection waits for a contended database lock before returning `Busy`. The default remains five seconds, and `Duration::ZERO` fails immediately on contention.

### Changed

- **Breaking:** `Options` now exposes only the transaction behavior, local encryption, and remote sync settings. Removed the pass-through engine builders `with_index_method`, `with_vacuum`, `with_attach`, `with_generated_columns`, and `with_without_rowid`, which only affected application SQL, and the engine-tuning builders `with_multiprocess_wal` and `with_mvcc_passive_checkpoint`. The crate now enables the matching Turso engine flags from the transaction behavior: `Concurrent` enables MVCC passive checkpointing, and the other behaviors enable multi-process WAL.
- **Breaking:** Removed the `Error::ConflictingOptions` variant, which only reported combinations of the removed builders.

## [0.3.2](https://crates.io/crates/bdk_turso/0.3.2) - 2026-11-16

### Added
Expand Down
47 changes: 31 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Each blocking call runs on a dedicated thread with its own Tokio runtime, so it

## Options and encryption

`Options::new()` leaves all experimental Turso settings disabled. Build the options before opening the store and pass them to `Store::new_with_options`, `Store::new_memory_with_options`, or `Store::new_remote_with_options`; the settings apply while Turso opens the database and cannot be changed on an open store.
`Options::new()` leaves every optional setting disabled. Build the options before opening the store and pass them to `Store::new_with_options`, `Store::new_memory_with_options`, or `Store::new_remote_with_options`; the settings apply while Turso opens the database and cannot be changed on an open store.

### Encryption

Expand All @@ -150,39 +150,54 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

Local encryption is not supported for remote sync stores, and Turso Cloud encryption does not encrypt the local cache; see [Remote Turso](#remote-turso).

### Other Turso options
### Transaction behavior

The remaining builders are pass-through engine settings. Except for `with_transaction_behavior`, they do not change the crate's schema or persistence queries; they only affect SQL that the application runs on the same database. The default schema already creates B-tree indexes for its lookup columns, so `with_index_method` is only needed for alternative index methods.
`Options` only exposes settings the crate acts on. Turso engine capabilities that affect only application SQL, such as `ATTACH DATABASE`, `VACUUM`, generated columns, `WITHOUT ROWID`, and alternative index methods, are not exposed. Open your own Turso database or run the corresponding SQL if an application needs them.

| Builder | What it enables | When to use it | Effect on `bdk_turso` queries |
`with_transaction_behavior` selects the `BEGIN` mode for every transaction the store opens:

| Behavior | What it changes | When to use it | Engine flags |
| --- | --- | --- | --- |
| `with_index_method` | Turso's experimental index methods, for example `CREATE INDEX ... USING toy_vector_sparse_ivf (...)` | Application SQL that needs a non-B-tree index method | None. Ordinary B-tree indexes are always available and the schema creates them; the flag is not needed for the crate's lookups. Turso's `fts` method is not compiled into the crate's default dependency build. |
| `with_multiprocess_wal` | Turso's WAL coordinator for sharing one file between operating-system processes | Several processes open the same database file | None. It adds cross-process locking and coordination; `Store` clones in one process already share a database handle. |
| `with_vacuum` | The `VACUUM` statement | Reclaiming space after large deletes or migrations | None. The crate never runs `VACUUM`; call it from application SQL. |
| `with_attach` | `ATTACH DATABASE` and `DETACH DATABASE` | Application SQL that joins another SQLite-compatible file | None. `migrate_to` copies tables without `ATTACH`. |
| `with_generated_columns` | Generated columns in application schemas | Application tables with computed columns | None. The crate schema has no generated columns and its `INSERT`/`SELECT` statements name columns explicitly. |
| `with_without_rowid` | `WITHOUT ROWID` table definitions | Application tables with composite primary keys that do not need a rowid | None. The crate schema does not use `WITHOUT ROWID`; `block` and `keychain` rely on integer rowid aliases. |
| `with_mvcc_passive_checkpoint` | Turso's experimental passive-checkpoint behavior for MVCC databases | Long-running MVCC workloads that need background checkpointing | None. It does not start a checkpoint. Select `Concurrent` through `with_transaction_behavior` (or enable MVCC externally) first. |
| `with_transaction_behavior` | The `BEGIN` mode for every transaction: `Deferred`, `Immediate`, `Exclusive`, or `Concurrent` | Tuning locking and write contention; `Concurrent` allows parallel writers | Applies to all crate transactions. `Concurrent` switches local databases to MVCC and is rejected for remote sync; migration still uses `Deferred` because Turso rejects DDL under `BEGIN CONCURRENT`. |
| `Deferred` (default) | Starts the transaction on first read or write | General use; avoids taking a write lock until a statement needs it | Multi-process WAL for file-backed local databases |
| `Immediate` | Acquires the write lock at `BEGIN` | Writes that should fail fast on contention instead of partway through | Multi-process WAL for file-backed local databases |
| `Exclusive` | Prevents other connections from reading while the transaction is open | Short operations that must block other readers | Multi-process WAL for file-backed local databases |
| `Concurrent` | Allows parallel writers with conflicts detected at commit; switches local databases to MVCC journal mode | Multi-writer workloads on local stores | MVCC passive checkpointing |

The four transaction behaviors are mutually exclusive because Turso stores one behavior per connection. Calling `with_transaction_behavior` again replaces the previous value; the last call wins. `with_multiprocess_wal` cannot be combined with `Concurrent`: Turso's MVCC mode does not support multi-process access, so the constructor returns `Error::ConflictingOptions`.
The four behaviors are mutually exclusive because Turso stores one behavior per connection. Calling `with_transaction_behavior` again replaces the previous value; the last call wins. `Concurrent` is rejected by remote sync stores, which always use multi-process WAL for the local cache. The engine flags in the last column are enabled automatically; they are not separate builders.

```rust,no_run
use bdk_turso::{Options, Store, TransactionBehavior};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let options = Options::new()
.with_attach()
.with_generated_columns()
.with_transaction_behavior(TransactionBehavior::Immediate);
let store = Store::new_with_options("wallet.sqlite", options).await?;
store.migrate().await?;
Ok(())
}
```

Local at-rest encryption and `with_mvcc_passive_checkpoint` are rejected by remote sync stores with an error, as is `TransactionBehavior::Concurrent`. `with_remote_encryption` is the only encryption option available to them; see [Remote Turso](#remote-turso).
Local at-rest encryption is rejected by remote sync stores with an error, as is `TransactionBehavior::Concurrent`. `with_remote_encryption` is the only encryption option available to them; see [Remote Turso](#remote-turso).

### Busy timeout

`Options::with_busy_timeout` controls how long a connection waits for a contended database lock before returning `Busy`. The default is **5 seconds**, matching the default used by `sqlx`'s SQLite driver. With the default, a writer waits out a short-lived lock instead of failing immediately; pass `Duration::ZERO` to fail as soon as the lock is contended.

The timeout applies to every connection the store opens, including the local cache of a remote sync store.

```rust,no_run
use std::time::Duration;
use bdk_turso::{Options, Store};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let options = Options::new().with_busy_timeout(Duration::from_secs(10));
let store = Store::new_with_options("wallet.sqlite", options).await?;
store.migrate().await?;
Ok(())
}
```

### Remote cache options

Expand Down
59 changes: 13 additions & 46 deletions benches/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ struct Config {
storage_changesets: u64,
/// Shape of each generated wallet changeset.
dataset: DatasetConfig,
/// Turso-specific benchmark options.
turso: TursoConfig,
/// Backends included in the run.
backends: BackendSelection,
}
Expand All @@ -173,7 +171,6 @@ impl Default for Config {
writers: vec![1, 2, 4, 8],
storage_changesets: 64,
dataset: DatasetConfig::default(),
turso: TursoConfig::default(),
backends: BackendSelection::default(),
}
}
Expand Down Expand Up @@ -297,22 +294,6 @@ impl DatasetConfig {
}
}

/// Turso-specific benchmark options.
#[derive(Clone, Debug, serde::Deserialize)]
#[serde(default, deny_unknown_fields)]
struct TursoConfig {
/// Open Turso with its opt-in multi-process WAL mode.
multiprocess_wal: bool,
}

impl Default for TursoConfig {
fn default() -> Self {
Self {
multiprocess_wal: true,
}
}
}

/// Backends included in the run.
#[derive(Clone, Debug, serde::Deserialize)]
#[serde(default, deny_unknown_fields)]
Expand Down Expand Up @@ -381,15 +362,10 @@ impl Dataset {

/// Turso options used by the benchmark.
///
/// Multi-process WAL is opt-in in `bdk_turso`; enabling it lets multiple connections take part in
/// the concurrent-write workload. All other experimental options stay disabled.
fn turso_options(config: &Config) -> bdk_turso::Options {
let options = bdk_turso::Options::new();
if config.turso.multiprocess_wal {
options.with_multiprocess_wal()
} else {
options
}
/// The default transaction behavior enables multi-process WAL automatically, so concurrent writers
/// can open their own database handles on the same file.
fn turso_options() -> bdk_turso::Options {
bdk_turso::Options::new()
}

fn benchmark_turso(
Expand All @@ -408,7 +384,7 @@ fn benchmark_turso(
let size_path = path_str(&size_path);

let store = runtime.block_on(async {
let store = TursoStore::new_with_options(work_path, turso_options(config)).await?;
let store = TursoStore::new_with_options(work_path, turso_options()).await?;
store.migrate().await?;
store.write_changeset(&dataset.changeset).await?;
anyhow::Ok(store)
Expand Down Expand Up @@ -445,7 +421,7 @@ fn benchmark_turso(
let stores = runtime.block_on(async {
let mut stores = Vec::with_capacity(writers);
for _ in 0..writers {
stores.push(TursoStore::new_with_options(work_path, turso_options(config)).await?);
stores.push(TursoStore::new_with_options(work_path, turso_options()).await?);
}
anyhow::Ok(stores)
})?;
Expand All @@ -462,15 +438,15 @@ fn benchmark_turso(
}

runtime.block_on(async {
let store = TursoStore::new_with_options(open_path, turso_options(config)).await?;
let store = TursoStore::new_with_options(open_path, turso_options()).await?;
store.migrate().await?;
store.write_changeset(&dataset.changeset).await?;
anyhow::Ok(())
})?;
let open = measure(config, config.open_batch, |operations| {
for _ in 0..operations {
runtime.block_on(async {
let store = TursoStore::new_with_options(open_path, turso_options(config))
let store = TursoStore::new_with_options(open_path, turso_options())
.await
.unwrap();
drop(store);
Expand All @@ -484,7 +460,7 @@ fn benchmark_turso(
));

runtime.block_on(async {
let store = TursoStore::new_with_options(size_path, turso_options(config)).await?;
let store = TursoStore::new_with_options(size_path, turso_options()).await?;
store.migrate().await?;
for changeset in &dataset.history {
store.write_changeset(changeset).await?;
Expand Down Expand Up @@ -1033,10 +1009,9 @@ fn render_report(

report.push_str("\n## Workload definition\n\n");
report.push_str(&format!(
"- bdk_turso is opened with `Options::new().with_multiprocess_wal()` when \
`turso.multiprocess_wal` is enabled; all other experimental options are disabled. Each \
Turso concurrent writer opens its own database handle on the same file. The other \
backends use their default constructors.\n\
"- bdk_turso is opened with `Options::new()`; the default transaction behavior enables \
multi-process WAL automatically. Each Turso concurrent writer opens its own database \
handle on the same file. The other backends use their default constructors.\n\
- Each changeset contains {} transactions, {} local-chain entries, {} cached scripts per \
descriptor, and {} locked outpoint(s), plus both descriptors and the network.\n\
- Write and read measurements reuse the same changeset, so the database stops growing \
Expand Down Expand Up @@ -1084,10 +1059,6 @@ fn render_configuration(config: &Config) -> String {
"dataset.locked_outpoints",
config.dataset.locked_outpoints.to_string(),
),
(
"turso.multiprocess_wal",
config.turso.multiprocess_wal.to_string(),
),
];

let mut report = String::from("\n## Configuration\n\n| Setting | Value |\n| --- | --- |\n");
Expand All @@ -1098,11 +1069,7 @@ fn render_configuration(config: &Config) -> String {
}

fn render_environment(config: &Config) -> String {
let turso_options = if config.turso.multiprocess_wal {
"multiprocess WAL enabled; other experimental options disabled"
} else {
"multiprocess WAL disabled; other experimental options disabled"
};
let turso_options = "default transaction behavior; multi-process WAL enabled automatically";
let mut rows: Vec<(&str, String)> = vec![
("bdk_turso", package_version("bdk_turso")),
("bdk_turso options", turso_options.to_owned()),
Expand Down
4 changes: 0 additions & 4 deletions benches/example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ blocks = 32
scripts_per_transaction = 8
locked_outpoints = 8

[turso]
# Open Turso with its opt-in multi-process WAL mode.
multiprocess_wal = true

[backends]
# Include or exclude backends from the run. At least one must be enabled.
turso = true
Expand Down
Loading
Loading