Skip to content

Spike: can Turso Database (the Rust SQLite rewrite) replace libsql in the local store #4015

Closed as not planned

Description

@malibio

Overview

The local store runs on the libsql crate (Cargo.toml: libsql = 0.6, core feature). Turso Database (formerly Limbo, the turso crate) is a from-scratch Rust rewrite of SQLite. It promises native async I/O, MVCC concurrent writes and built-in vector search, and it would remove the C libsql-ffi build and the libsql-sys rusqlite Windows-path workaround in packages/core/Cargo.toml.

This spike answers one question: can the turso crate run our schema and our heaviest queries, and how does it compare with libsql? The store leans on features a rewrite tends to support late, so a hard gap would end the idea.

Problem Statement

We don't know whether Turso supports what the store depends on. Usage in packages/core/src/db:

Dependency Usage
WITH RECURSIVE about 20 queries, relationship and path walks
json_extract / json_each about 60 call sites
CREATE TRIGGER 18
FTS5 node_title_fts (schema.rs)
vec0 (sqlite-vec) vec_embeddings for KNN search (schema.rs, sqlite_store/embeddings.rs)
journal_mode / busy_timeout WAL and writer-contention tuning on connections

Proposed Solution

Time-boxed investigation in a disposable worktree. The spike code is discarded and nothing is merged.

  1. Add turso to a scratch crate or test, not to the workspace.
  2. Run create_schema DDL against it and record each statement that fails: triggers, FTS5, vec0, indexes.
  3. Run the relationship-path recursive CTEs against both engines on the same generated graph. Record support, result equality and timing.
  4. Run representative json_extract / json_each property queries on both engines.
  5. Check vector search with Turso's native vector functions in place of vec0.
  6. Check concurrent-writer behavior (MVCC) against libsql under busy_timeout.
  7. Post the findings on this issue and delete the worktree.

Documentation

  • ADR-069 - the transaction seam any engine swap must preserve
  • write-atomicity-inventory - the atomic write paths the new engine would have to keep
  • ADR-053 - one daemon owns several databases, so multi-database handling matters for an engine swap
  • ADR-054 - the store's encryption stance
  • data-layer.md - to be updated only if a migration is later decided

Architecture Impact

The docs mention libsql as the store but contain no ADR that selects it over alternatives. This spike changes no decision. If the findings favor switching, a new ADR is required before any migration issue is filed, and that is out of scope here.

Acceptance Criteria

  • Each engine feature in the table above has a pass, partial or fail result with the failing statement or error recorded
  • Recursive CTE results match libsql on the same graph, with timings for both engines
  • A vector-search result: native Turso vectors against vec0, on a small fixed data set
  • A concurrent-write result against libsql's single-writer behavior
  • Findings posted as a comment on this issue with the pass/fail table and a go / no-go recommendation
  • Spike worktree removed, nothing merged to main, no turso dependency left in the workspace

Technical Specifications

Reference Files

  • Cargo.toml - workspace libsql pin
  • packages/core/Cargo.toml - libsql-sys rusqlite workaround to be removed if Turso is adopted
  • packages/core/src/db/schema.rs - DDL, including node_title_fts and vec_embeddings
  • packages/core/src/db/sqlite_store/relationship_paths.rs - recursive CTEs
  • packages/core/src/db/sqlite_store/embeddings.rs - KNN search through vec0
  • packages/core/src/db/sqlite_store/connections.rs - connection pragmas

Notes

  • The correlated-subquery form of the relationship-walk CTE is about 50x faster than the JOIN form on libsql and is plan-tested. Check that Turso doesn't lose that advantage.
  • Don't touch the production code path. The spike lives in a scratch crate or an ignored test.

Non-Goals

  • Migrating the store or writing any adapter layer
  • Data migration, since the database can be reset
  • Merging spike code

Activity

  1. self-assigned this
    on Oct 27, 2026
  2. malibio commented on Oct 27, 2026

    @malibio
    CollaboratorAuthor

    Spike round 1: SQL feature support (turso 0.9.0-pre.1 vs libsql 0.6)

    Scratch crate outside the repo, in-memory databases. The graph is 5000 has_child edges with fanout 2, and the recursive query is the production shape: a correlated json_group_array subquery feeding json_each.

    Feature libsql turso Results equal
    WITH RECURSIVE (counter) pass pass yes
    WITH RECURSIVE + correlated subquery + json_each (full walk, 5000 nodes) pass pass yes (5000)
    WITH RECURSIVE walk from a leaf-ish node pass pass yes (3)
    WITH RECURSIVE reverse walk (JOIN form) pass pass yes (13)
    CREATE TRIGGER AFTER INSERT, and it fires pass pass yes
    json_extract filter and nested path pass pass yes
    json_each aggregate pass pass yes
    vector_distance_cos / vector32 pass pass yes (0.2929)
    fts5 virtual table pass fail (no such module: fts5) n/a
    Full-text search, engine-specific form n/a pass via CREATE INDEX ... USING fts and fts_match() (needs experimental_index_method(true)) same hit

    Recursive CTEs are supported and give the same results. That was the deal-breaker question.

    Timing on the full walk was 6.6 ms on libsql and 14.0 ms on turso, with the same indexed access. That is one cold run on a micro-graph, so it shows no pathological blowup but is not a benchmark.

    FTS is the real difference. There is no FTS5 virtual table. Turso has its own index-method FTS, behind an experimental flag. node_title_fts and its triggers/queries would have to be rewritten.

    Not yet covered:

    • On-disk behavior (WAL, busy_timeout, concurrent writers / MVCC)
    • vec0 KNN against Turso's native vector index
    • The full create_schema DDL
    • A real timing comparison on a larger, warm graph
  3. malibio commented on Nov 16, 2026

    @malibio
    CollaboratorAuthor

    Closing as not planned for now. Recommendation: no-go at this time.

    Round 1 (above) showed the hard question passes: recursive CTEs, triggers, json_extract/json_each and vector distance all run on turso and match libsql. The blocker is full-text search. Turso has no fts5 module (no such module: fts5); its own FTS is an index method behind an experimental flag, so node_title_fts, its triggers and its queries would need a rewrite. The version tested, 0.9.0-pre.1, is also a pre-release.

    Not run: on-disk behaviour (WAL, busy_timeout, concurrent writers/MVCC), vec0 KNN against Turso's native vector index, the full create_schema DDL, and a warm-graph benchmark (the one cold run was 14.0 ms on turso vs 6.6 ms on libsql).

    Revisit when Turso ships FTS5 support or a stable release. No turso dependency was added to the workspace; the scratch crate lived outside the repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions