Experiment 031: JSON1 Bulk Shapes

Date: 2026-04-08

Status: Rejected

Hypothesis

SQLite's JSON1 extension can trade many bound parameters for one JSON payload.

That could help resqlite in two places where host-side overhead still matters:

The most important question was not just "is JSON1 fast?", but:

  1. does it beat the existing bind path when JSON encoding is included?
  2. does it only help when the payload is already available as JSON?

Change

Added a targeted experiment script:

It measures three variants for each workload:

  1. current bind-heavy baseline
  2. JSON1 with jsonEncode(...) inside the measured path
  3. JSON1 with a pre-encoded payload

Workloads:

The JSON1 shapes use json_each(?):

 WITH rows AS ( SELECT json_extract(value, '$[0]') AS name, json_extract(value, '$[1]') AS email FROM json_each(?) ) INSERT INTO customers(name, email) SELECT name, email FROM rows 

and:

 SELECT id, name, email FROM customers WHERE id IN (SELECT value FROM json_each(?)) ORDER BY id 

Results

Two process-level runs showed the same overall pattern even though the insert

baseline was noisier than the read cases.

Run 1

WorkloadBaselineJSON1 + encodeJSON1 + pre-encoded
Insert 5000 rows3.49ms4.22ms2.87ms
Read 1000 ids0.60ms0.76ms0.39ms
Read 5000 ids1.78ms2.19ms2.00ms

Run 2

WorkloadBaselineJSON1 + encodeJSON1 + pre-encoded
Insert 5000 rows8.30ms4.30ms3.10ms
Read 1000 ids0.81ms0.67ms0.42ms
Read 5000 ids2.78ms2.37ms2.20ms

Interpretation

The directional signal is clearer than the raw numbers:

So the real win is not "JSON1 beats binds". The real win is:

> when the app already has the payload as JSON, JSON1 can sometimes replace a

> lot of host-side bind overhead cheaply.

That is a much narrower claim.

Decision

Rejected as a default resqlite runtime optimization.

Reasons:

better expressed at the query layer

Takeaway

JSON1 is still a useful tool, just not a blanket optimization.

The practical guidance is:

That makes it a query-shape optimization, not a resqlite architecture change.