Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
08f94ae
@austinm911's changes to add first-class expo integrations
austinm911 Feb 14, 2025
9b3e643
fix: only have zero-expo
0xcadams Jul 23, 2025
3c3c2ba
feat: added expo sqlite
0xcadams Jul 25, 2025
0c8bbfb
fix: remove unused prepared statements
0xcadams Jul 25, 2025
e0c0bee
fix: entrypoint
0xcadams Jul 25, 2025
0b78396
fix: cleanup
0xcadams Jul 25, 2025
5e867f8
Merge branch 'main' into 0xcadams/expo
0xcadams Jul 25, 2025
0e0e73c
fix: add back WITHOUT ROWID
0xcadams Jul 25, 2025
5fc9311
Merge remote-tracking branch 'origin/0xcadams/expo' into 0xcadams/expo
0xcadams Jul 25, 2025
edaca04
chore: fix global types
0xcadams Jul 25, 2025
59e6b7c
chore: update peer dep version
0xcadams Jul 25, 2025
de0b1a9
fix: move to use tx/savepoint for reads
0xcadams Jul 28, 2025
99c12e8
test: simplify bench
0xcadams Jul 28, 2025
e0b779e
fix: moved defaults to be config and fixed test config
0xcadams Jul 31, 2025
c726a5c
Merge branch 'main' into 0xcadams/expo
0xcadams Jul 31, 2025
caf8fc1
fix: test config
0xcadams Jul 31, 2025
f9ff100
Merge branch 'main' into 0xcadams/expo
0xcadams Aug 1, 2025
1a0de26
fix: move to use read pool and single write conn
0xcadams Aug 1, 2025
fd47385
Merge remote-tracking branch 'origin/0xcadams/expo' into 0xcadams/expo
0xcadams Aug 1, 2025
1320e5c
Merge remote-tracking branch 'origin/main' into 0xcadams/expo
0xcadams Aug 1, 2025
891d60a
fix: remove readonly flag
0xcadams Aug 1, 2025
3d536a4
Merge branch 'main' into 0xcadams/expo
0xcadams Aug 4, 2025
b430406
Merge branch 'main' into 0xcadams/expo
0xcadams Aug 5, 2025
0710a6d
fix: update based on @arv feedback
0xcadams Aug 7, 2025
5eada28
fix: rename
0xcadams Aug 7, 2025
baae8b6
Merge branch 'main' into 0xcadams/expo
0xcadams Aug 7, 2025
57d26d3
Merge branch 'main' into 0xcadams/expo
0xcadams Aug 7, 2025
c9b14ce
Merge branch 'main' into 0xcadams/expo
0xcadams Aug 7, 2025
589d170
Merge branch 'main' into 0xcadams/expo
0xcadams Aug 7, 2025
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
2 changes: 2 additions & 0 deletions eslint-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"zero/*",
"zero-cache/*",
"zero-client/*",
"zero-expo/*",
"zero-protocol/*",
"zero-react/*",
"zero-schema/*",
Expand Down Expand Up @@ -58,6 +59,7 @@
{"name": "zero", "message": "Use relative imports instead"},
{"name": "zero-cache", "message": "Use relative imports instead"},
{"name": "zero-client", "message": "Use relative imports instead"},
{"name": "zero-expo", "message": "Use relative imports instead"},
{"name": "zero-protocol", "message": "Use relative imports instead"},
{"name": "zero-react", "message": "Use relative imports instead"},
{"name": "zero-schema", "message": "Use relative imports instead"},
Expand Down
9,258 changes: 9,011 additions & 247 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/replicache/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ perf/index.js.map
perf/index.js
tool/bump/bump
.vscode/launch.json
src/kv/*.db*
2 changes: 2 additions & 0 deletions packages/replicache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"scripts": {
"test": "vitest run",
"test:watch": "vitest",
"bench": "vitest bench --run",
"bench:watch": "vitest bench --watch",
"format": "prettier --write .",
"check-format": "prettier --check .",
"check-types": "tsc && tsc --project tool/tsconfig.json",
Expand Down
54 changes: 54 additions & 0 deletions packages/replicache/src/kv/sqlite-store-test-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-disable no-console */
import sqlite3 from '@rocicorp/zero-sqlite3';
import fs from 'fs';
import path from 'path';
import {SQLiteDatabaseManager} from './sqlite-store.ts';

export const getTestSQLiteDatabaseManager = (logging: boolean = false) =>
new SQLiteDatabaseManager({
open: name => {
const filename = path.resolve(__dirname, `${name}.db`);
// this cannot be :memory: because multiple read connections must access
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's technically doable via memory with some fancy options. But yeah, better to just keep it file based.

// the same database
const db = sqlite3(filename);
return {
close: () => {
db.close();
},
destroy: () => {
db.close();
if (fs.existsSync(filename)) {
fs.unlinkSync(filename);
}
},
prepare: (sql: string) => {
const stmt = db.prepare(sql);
if (logging) {
console.log('prepare', sql);
}
return {
all: <T>(...params: unknown[]): T[] => {
const result = params.length ? stmt.all(...params) : stmt.all();
if (logging) {
console.log('all', sql, params, result);
}
return result as T[];
},
run: (...params: unknown[]): void => {
if (logging) {
console.log('run', sql, params);
}
if (params.length) {
stmt.run(...params);
} else {
stmt.run();
}
},
finalize: () => {
// no-op
},
};
},
};
},
});
202 changes: 202 additions & 0 deletions packages/replicache/src/kv/sqlite-store.bench.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import {afterAll, bench, describe, expect} from 'vitest';
import {withRead, withWrite} from '../with-transactions.ts';
import {getTestSQLiteDatabaseManager} from './sqlite-store-test-util.ts';
import {createSQLiteStore} from './sqlite-store.ts';

const walSQLite3DatabaseManager = getTestSQLiteDatabaseManager();
const createWalStore = createSQLiteStore(walSQLite3DatabaseManager);
const walStore = createWalStore('bench-wal', {
readPoolSize: 2,
journalMode: 'WAL',
synchronous: 'NORMAL',
readUncommitted: false,
});

const defaultSQLite3DatabaseManager = getTestSQLiteDatabaseManager();
const createDefaultStore = createSQLiteStore(defaultSQLite3DatabaseManager);
const defaultStore = createDefaultStore('bench-default', {
readPoolSize: 2,
synchronous: 'NORMAL',
readUncommitted: false,
});

afterAll(() => {
walSQLite3DatabaseManager.clearAllStoresForTesting();
defaultSQLite3DatabaseManager.clearAllStoresForTesting();
});

describe('sqlite tx', () => {
bench(
`default journal mode`,
async () => {
await withWrite(defaultStore, async wt => {
expect(await wt.get('bar')).equal(undefined);
await wt.put('bar', 'baz');
expect(await wt.get('bar')).equal('baz');
await wt.del('bar');
expect(await wt.get('bar')).equal(undefined);
});
},
{
throws: true,
},
);

bench(
`WAL journal mode`,
async () => {
await withWrite(walStore, async wt => {
expect(await wt.get('bar')).equal(undefined);
await wt.put('bar', 'baz');
expect(await wt.get('bar')).equal('baz');
await wt.del('bar');
expect(await wt.get('bar')).equal(undefined);
});
},
{
throws: true,
},
);
});

describe('sqlite write contention', () => {
bench(
`default journal mode`,
async () => {
await withWrite(defaultStore, async wt => {
await wt.put('foo', 'bar');
});

const readP1 = withRead(defaultStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP2 = withRead(defaultStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP3 = withRead(defaultStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP4 = withRead(defaultStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP5 = withRead(defaultStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const writeP = withWrite(defaultStore, async wt => {
await wt.put('foo', 'bar2');
});

await Promise.all([readP1, readP2, readP3, readP4, readP5, writeP]);
},
{
throws: true,
teardown: async () => {
await withWrite(defaultStore, async wt => {
await wt.del('foo');
});
},
},
);

bench(
`WAL journal mode`,
async () => {
await withWrite(walStore, async wt => {
await wt.put('foo', 'bar');
});

const readP1 = withRead(walStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP2 = withRead(walStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP3 = withRead(walStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP4 = withRead(walStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP5 = withRead(walStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const writeP = withWrite(walStore, async wt => {
await wt.put('foo', 'bar2');
});

await Promise.all([readP1, readP2, readP3, readP4, readP5, writeP]);
},
{
throws: true,
setup: async () => {
await withWrite(walStore, async wt => {
await wt.del('foo');
});
},
},
);
});

describe('plain read', () => {
bench(
`default journal mode`,
async () => {
const readP1 = withRead(defaultStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP2 = withRead(defaultStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP3 = withRead(defaultStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP4 = withRead(defaultStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP5 = withRead(defaultStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});

await Promise.all([readP1, readP2, readP3, readP4, readP5]);
},
{
throws: true,
setup: async () => {
await withWrite(defaultStore, async wt => {
await wt.put('foo', 'bar');
});
},
},
);

bench(
`WAL journal mode`,
async () => {
const readP1 = withRead(walStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP2 = withRead(walStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP3 = withRead(walStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP4 = withRead(walStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});
const readP5 = withRead(walStore, async rt => {
expect(await rt.get('foo')).equal('bar');
});

await Promise.all([readP1, readP2, readP3, readP4, readP5]);
},
{
throws: true,
setup: async () => {
await withWrite(walStore, async wt => {
await wt.put('foo', 'bar');
});
},
},
);
});
Loading
Loading