Compare commits

..

No commits in common. "de9280186debb99b2dc55fa423ed4886840b4ce7" and "71a1f6fae73c9dca4226629e9d6560739bb75c07" have entirely different histories.

3 changed files with 44 additions and 126 deletions

@ -23,7 +23,6 @@
},
"dependencies": {
"@sqlite.org/sqlite-wasm": "^3.45.1-build1",
"esbuild-plugin-inline-worker": "^0.1.1",
"localforage": "^1.10.0"
"esbuild-plugin-inline-worker": "^0.1.1"
}
}

@ -1,33 +1,26 @@
import { Notice, Plugin } from "obsidian";
import * as localforage from "localforage";
import {
Notice,
Plugin,
} from "obsidian";
import TestWorker from "sqlite3.worker";
import { sqlite3Worker1Promiser } from "@sqlite.org/sqlite-wasm";
// Remember to rename these classes and interfaces!
interface Benchmark {
time: number;
name: string;
}
export default class MyPlugin extends Plugin {
public persister: LocalForage;
settings: any;
private worker: Worker;
private promiser: (...args: any[]) => any;
public benches: Benchmark[] = [];
private dbId: string;
async onload() {
await this.loadSettings();
this.benches.push(
await this.time("sqlite-init", async () => await this.initSqlite())
);
await this.sqlite();
this.benches.push(
await this.time("idb-init", async () => await this.initIDB())
);
await this.idb();
console.table(this.benches)
console.log(import.meta);
await this.initSqlite();
await this.start();
(window as any).sqlite3Promiser = this.promiser;
}
onunload() {
@ -48,28 +41,10 @@ export default class MyPlugin extends Plugin {
}
locateFile(path: string, prefix: string): string {
return this.app.vault.adapter.getResourcePath(
`${this.manifest.dir}/${path}`
`${this.manifest.dir}/${path}`,
);
}
async time(benchName: string, func: () => Promise<void>): Promise<Benchmark> {
const start = performance.now();
await func();
const end = performance.now();
return {
name: benchName,
time: end - start,
};
}
async initIDB() {
this.persister = localforage.createInstance({
name: "sqlite-bench",
driver: localforage.INDEXEDDB,
description: "we do a little benchmarking",
});
}
async initSqlite() {
this.worker = new TestWorker();
let w = this.worker;
@ -88,81 +63,44 @@ export default class MyPlugin extends Plugin {
worker: () => w,
});
});
(window as any).sqlite3Promiser = this.promiser;
}
async doInsert(each: (s: number) => Promise<void>) {
for (let i = 0; i < 50; i++) {
await each(i);
}
}
async sqlite() {
this.benches.push(
await this.time("sqlite-open", async () => {
let openRes = await this.promiser("open", {
filename: "/managed-sah/test.sqlite3",
vfs: "opfs-sahpool",
});
const { dbId } = openRes;
this.dbId = dbId;
console.log(openRes);
})
);
async start() {
let openRes = await this.promiser("open", {
filename: "/managed-sah/test.sqlite3",
vfs: "opfs-sahpool",
});
const { dbId } = openRes;
console.log(openRes);
try {
this.benches.push(await this.time("sqlite-create-table", async () => {
console.log("Creating a table...");
let res = await this.promiser("exec", {
dbId: this.dbId,
sql: "DROP TABLE IF EXISTS abcdef; CREATE TABLE IF NOT EXISTS abcdef(a,b,c)",
let res = await this.promiser("exec", {
dbId,
sql: "DROP TABLE IF EXISTS abcdef; CREATE TABLE IF NOT EXISTS abcdef(a,b,c)",
returnValue: "resultRows",
});
console.log("Result: ", res);
console.log("Insert some data using exec()...");
for (let i = 20; i <= 25; ++i) {
let innerRes = await this.promiser("exec", {
dbId,
sql: "INSERT INTO abcdef(a,b,c) VALUES (?,?,69)",
bind: [i, i * 2],
returnValue: "resultRows",
rowMode: "object",
});
console.log("Result: ", res);
}));
this.benches.push(
await this.time("sqlite-insert-many", async () => {
console.log("Insert some data using exec()...");
await this.doInsert(async (i) => {
let innerRes = await this.promiser("exec", {
dbId: this.dbId,
sql: "INSERT INTO abcdef(a,b,c) VALUES (?,?,69)",
bind: [i, i * 2],
returnValue: "resultRows",
rowMode: "object",
});
// console.log(innerRes);
});
})
);
this.benches.push(
await this.time("sqlite-query-many", async () => {
console.log("Query data with exec()...");
let rowRes = await this.promiser("exec", {
dbId: this.dbId,
sql: "SELECT * FROM abcdef ORDER BY a LIMIT 50",
returnValue: "resultRows",
rowMode: "object",
});
console.log(rowRes);
})
);
console.log(innerRes);
}
console.log("Query data with exec()...");
let rowRes = await this.promiser("exec", {
dbId,
sql: "SELECT * FROM abcdef ORDER BY a LIMIT 10",
returnValue: "resultRows",
rowMode: "object",
});
console.log(rowRes);
} finally {
await this.promiser("close", { dbId: this.dbId });
await this.promiser("close", { dbId });
}
}
async idb() {
this.benches.push(await this.time("idb-insert-many", async() => {
await this.doInsert(async (s) => {
await this.persister.setItem("i/" +s, "brian tatler fucked and abused sean harris\n".repeat(Math.floor(s * 1.1)))
})
}))
this.benches.push(await this.time("idb-query-many", async() => {
let q: any[] = [];
await this.doInsert(async (s) => {
q.push(await this.persister.getItem("i/" + s))
})
console.log("qlen", q.length)
}))
}
}

@ -576,11 +576,6 @@ ignore@^5.2.0:
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.1.tgz#5073e554cd42c5b33b394375f538b8593e34d4ef"
integrity sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==
immediate@~3.0.5:
version "3.0.6"
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
integrity sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==
is-extglob@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"
@ -598,20 +593,6 @@ is-number@^7.0.0:
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==
lie@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/lie/-/lie-3.1.1.tgz#9a436b2cc7746ca59de7a41fa469b3efb76bd87e"
integrity sha512-RiNhHysUjhrDQntfYSfY4MU24coXXdEOgw9WGcKHNeEwffDYbF//u87M1EWaMGzuFoSbqW0C9C6lEEhDOAswfw==
dependencies:
immediate "~3.0.5"
localforage@^1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/localforage/-/localforage-1.10.0.tgz#5c465dc5f62b2807c3a84c0c6a1b1b3212781dd4"
integrity sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==
dependencies:
lie "3.1.1"
locate-path@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0"