## Summary
`push()` in `@tursodatabase/sync` (Node) used roughly 14–20x the size of
the change set in RSS. A user pushing a ~50 MB change set saw a +900 MB
RSS peak and had to set `pushOperationsThreshold` to avoid OOM kills in
CI. The dominant cost was not the sync engine but the napi boundary: the
serialized HTTP request body was handed to JavaScript as a plain
`Array<number>`, one element per byte.
This PR passes the body (and `FullWrite` content) across the boundary as
a napi `Buffer` instead, and drops the extra `Uint8Array` copy on the JS
side.
## Root cause
`JsProtocolRequest::Http { body: Option<Vec<u8>>, .. }` and `FullWrite {
content: Vec<u8> }` are fields of a `#[napi]` enum. napi-rs marshals
`Vec<u8>` as a JS array of numbers (the generated typing was `body?:
Array<number>`). V8 stores such an array at 8 bytes per element, so a 21
MiB JSON body became a ~170 MiB array before `run.ts` copied it again
with `new Uint8Array(requestType.body)` and undici buffered it once
more.
Everything else in the push path (decoded CDC row images, the
`BatchStep` vector, the JSON body, undici's copy) adds up to a few
multiples of the body, which is what remains after this change.
## Changes
- `bindings/javascript/sync/src/js_protocol_io.rs`: `Http.body` is
`Option<Buffer>`, `FullWrite.content` is `Buffer`. Both are built with
`Buffer::from(Vec<u8>)`, which takes ownership of the allocation without
copying.
- `bindings/javascript/sync/packages/common/run.ts`: pass the buffer
straight to `fetch`; a `Buffer` is already a `Uint8Array`.
- `bindings/javascript/sync/packages/native/index.d.ts`: the two
generated types updated to `Buffer`.
- `bindings/javascript/sync/packages/native/promise.test.ts`: new
regression test.
No sync-engine (Rust core) changes. The wasm package shares this Rust
code and its `write()` implementations already accept `Buffer |
Uint8Array`, so `FullWrite` needs no JS follow-up there.
## Measurements
Same test (`push()` of one 16 MiB blob, 21.3 MiB JSON body), same
machine, debug builds:
| Build | RSS growth during `push()` | Multiple of body |
|---|---|---|
| Without this change | 296 MiB | 13.9x |
| With this change | 83 MiB | 3.9x |
Standalone, holding 50 MiB of bytes as a JS `Array<number>` cost 1080
MiB of RSS on Node 26 versus 50 MiB as a `Uint8Array`, which matches the
user report almost exactly.
Closes#8635
Syncing against an MVCC-mode database requires the sync engine to use
logical-log
pulls, but this was gated behind an opt-in flag (`logical_mvcc_pull`)
that the JS,
Python, Go, and react-native SDKs never exposed. Every SDK client
pulling from an
MVCC database bootstrapped a stale base and then failed with:
```
status=400 "MVCC incremental pull-updates requires stream_kind=mvcc_logical_log"
```
Even after plumbing the flag through, users would have to know their
database's
journal mode and configure the client accordingly/we don't want to force
a client to configure this flag.
The protocol is a property of the server, so the client should learn it
there.
## Solution
The server now advertises its pull protocol in every pull-updates
response.
The engine reads it on first contact and persists it in the sync
metadata:
- New `remote_pull_protocol` field in `DatabaseMetadata`: `unknown`,
`pages`,
or `mvcc_logical`. Old metadata files deserialize to `unknown` and are
migrated on load from the existing `logical_mvcc_pull_active` bool
whenever
the replica already holds a revision.
- `DatabaseSyncEngineOpts.logical_mvcc_pull` is now `Option<bool>`.
`None`
(the new default) auto-detects; `Some(true/false)` forces a protocol
and
remains available in every SDK as an escape hatch.
`Builder::with_logical_mvcc_pull`
keeps its signature.
- For servers that predate the header field, detection falls back to the
shape
of the advertised revision: MVCC revisions contain `log_offset`, WAL
diskless
revisions only `generation`/`wal_fragment_no`.
- A replica created with deferred bootstrap stays `unknown` until its
first
pull; that request is wire-identical to the existing no-revision page
request,
so the response tells us the protocol before any mode-specific
behavior kicks in.
- Partial sync or remote encryption combined with an MVCC remote is now
a hard
error at configuration/detection time.
### Deferred bootstrap ("converted to cloud sync later")
A replica created with deferred bootstrap has already committed to a
local
journal mode before the remote's protocol is knowable. When first
contact
detects an MVCC remote and the local database is still in WAL mode, the
engine now converts it in place with `PRAGMA journal_mode = 'mvcc'`
(core
already implements the full transition for populated databases: WAL
checkpoint, header rewrite, MvStore bootstrap over the existing btree)
before applying the remote base as replace-base. Local changes survive
via
the existing CDC replay, and the conversion is durable across reopens.
Without this, applying an MVCC-headered base into a WAL-mode process
would
leave the file header and the running journal mode disagreeing: the
process
keeps WAL semantics while the next open reads the MVCC header and starts
an
empty MvStore: essentially an uncoordinated journal mode flip across
restarts.
### CDC Guard
also added here: since `replace-base` preserves local data by replaying
the CDC log, so a database file that lived outside
the sync engine (user tables present but an empty CDC log before the
first sync) is rejected with a
descriptive error instead of silently dropping its rows.
Reviewed-by: Nikita Sivukhin (@sivukhin)
Closes#8057
The sync packages (Rust, Python, JavaScript, React Native, Go) only
rewrote libsql:// remote URLs to https://, so turso:// URLs were either
rejected or passed through unmodified and failed at request time. The
serverless packages already accept both schemes; normalize turso:// the
same way in every sync binding so the two URL forms are interchangeable.
Tests: normalize_base_url_schemes in bindings/rust, TestSyncNormalizeUrl
in bindings/go
0.7 ships next week, and Turso now runs in production at multiple
organizations — the top-of-page "this software is in BETA, use caution
with production data" warning no longer reflects reality, and it's the
first thing every visitor reads.
## What changed
- **About**: the ⚠️ BETA warning blockquote is gone. In its place, a
one-line status note: Turso runs in production today, with a pointer to
the FAQ for where the project stands on the way to 1.0.
- **FAQ "Is Turso Database ready for production use?"**: now opens with
"Yes" and the production users, followed by the testing story (DST,
Antithesis). The honest caveats stay, but softened: not yet 1.0, some
features explicitly experimental, and backups recommended as "the same
discipline you would apply to any database" rather than as a data-loss
threat.
- **New FAQ "How compatible is Turso Database with SQLite?"**: we're not
at 100% yet, COMPAT.md tracks the details, the gap is closing quickly,
and full compatibility is a requirement for 1.0.
- **libSQL FAQ**: still flatly said "libSQL is production ready, Turso
Database is not", contradicting the rest of the page. Now: both run in
production; libSQL is more battle-tested, Turso Database is where
development effort is focused.
The goal is to neither scare nor oversell: no data-loss warning up top,
but the README still says clearly that we are pre-1.0 and that some
SQLite differences remain.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Reviewed-by: Mikaël Francoeur (@LeMikaelF)
Closes#7735
On browser wasm the binding executes core code on two threads: statement
stepping runs on the main thread while the sync engine's resumeAsync and
ioLoopAsync AsyncTasks run core work on the napi async worker. parking_lot
cannot park on the browser main thread (its spin phase is a no-op and the
wasm parker panics), so any cross-thread contention on a core lock aborts
the call mid-flight, leaking every lock it held and poisoning the whole
instance. Observed as "Parking not supported on this platform" panic storms
in the browser sync test job, first contended lock being the db.schema
mutex via Statement::reprepare racing a pull that bumped the schema cookie.
Hold the connection's exec lock around every window where a sync-engine
native call is in flight, so main-thread statement execution and worker-side
engine steps interleave without overlapping. The lock is released between
steps, keeping long-polls from starving execution. The native binding is
unchanged: parking works there and exec/sync parallelism is kept.
Tests: no-native-call-overlap-with-worker-tasks (wasm) instruments the
native entry points and counts overlapping main-thread steps; 50 without
the serialization, 0 with it. The concurrent-updates flake reproduced in
<=3 filtered runs before and is clean over 20 runs after.
Turso runs in production at multiple organizations, so the "this
software is in BETA, use caution with production data" warning no
longer reflects reality. It appeared in the main README, was
copy-pasted in 11 bindings READMEs (what users see on npm, PyPI, and
pkg.go.dev), and was printed by tursodb at every shell startup.
- README: remove the warning blockquote from About, leaving a one-line
status pointer. Rewrite the production-readiness FAQ to lead with
production use and the testing story, keeping the honest caveats in
softer form: not yet 1.0, some features experimental, keep backups
as with any database. Add a FAQ on SQLite compatibility (gap tracked
in COMPAT.md, closing quickly, required for 1.0), and fix the libSQL
FAQ, which still claimed Turso Database is not production ready.
- bindings READMEs: replace the warning with the same softened status
line, linking to the FAQ.
- cli: remove the startup banner line entirely, matching the SQLite
shell.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>