Compare commits
No commits in common. "de9280186debb99b2dc55fa423ed4886840b4ce7" and "71a1f6fae73c9dca4226629e9d6560739bb75c07" have entirely different histories.
de9280186d
...
71a1f6fae7
@ -23,7 +23,6 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sqlite.org/sqlite-wasm": "^3.45.1-build1",
|
"@sqlite.org/sqlite-wasm": "^3.45.1-build1",
|
||||||
"esbuild-plugin-inline-worker": "^0.1.1",
|
"esbuild-plugin-inline-worker": "^0.1.1"
|
||||||
"localforage": "^1.10.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
104
src/main.ts
104
src/main.ts
@ -1,33 +1,26 @@
|
|||||||
import { Notice, Plugin } from "obsidian";
|
import {
|
||||||
import * as localforage from "localforage";
|
Notice,
|
||||||
|
Plugin,
|
||||||
|
} from "obsidian";
|
||||||
import TestWorker from "sqlite3.worker";
|
import TestWorker from "sqlite3.worker";
|
||||||
import { sqlite3Worker1Promiser } from "@sqlite.org/sqlite-wasm";
|
import { sqlite3Worker1Promiser } from "@sqlite.org/sqlite-wasm";
|
||||||
|
|
||||||
// Remember to rename these classes and interfaces!
|
// Remember to rename these classes and interfaces!
|
||||||
|
|
||||||
interface Benchmark {
|
|
||||||
time: number;
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class MyPlugin extends Plugin {
|
export default class MyPlugin extends Plugin {
|
||||||
public persister: LocalForage;
|
|
||||||
settings: any;
|
settings: any;
|
||||||
private worker: Worker;
|
private worker: Worker;
|
||||||
private promiser: (...args: any[]) => any;
|
private promiser: (...args: any[]) => any;
|
||||||
public benches: Benchmark[] = [];
|
|
||||||
private dbId: string;
|
|
||||||
async onload() {
|
async onload() {
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
this.benches.push(
|
console.log(import.meta);
|
||||||
await this.time("sqlite-init", async () => await this.initSqlite())
|
|
||||||
);
|
await this.initSqlite();
|
||||||
await this.sqlite();
|
await this.start();
|
||||||
this.benches.push(
|
(window as any).sqlite3Promiser = this.promiser;
|
||||||
await this.time("idb-init", async () => await this.initIDB())
|
|
||||||
);
|
|
||||||
await this.idb();
|
|
||||||
console.table(this.benches)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onunload() {
|
onunload() {
|
||||||
@ -48,28 +41,10 @@ export default class MyPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
locateFile(path: string, prefix: string): string {
|
locateFile(path: string, prefix: string): string {
|
||||||
return this.app.vault.adapter.getResourcePath(
|
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() {
|
async initSqlite() {
|
||||||
this.worker = new TestWorker();
|
this.worker = new TestWorker();
|
||||||
let w = this.worker;
|
let w = this.worker;
|
||||||
@ -88,81 +63,44 @@ export default class MyPlugin extends Plugin {
|
|||||||
worker: () => w,
|
worker: () => w,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
(window as any).sqlite3Promiser = this.promiser;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async doInsert(each: (s: number) => Promise<void>) {
|
async start() {
|
||||||
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", {
|
let openRes = await this.promiser("open", {
|
||||||
filename: "/managed-sah/test.sqlite3",
|
filename: "/managed-sah/test.sqlite3",
|
||||||
vfs: "opfs-sahpool",
|
vfs: "opfs-sahpool",
|
||||||
});
|
});
|
||||||
const { dbId } = openRes;
|
const { dbId } = openRes;
|
||||||
this.dbId = dbId;
|
|
||||||
console.log(openRes);
|
console.log(openRes);
|
||||||
})
|
|
||||||
);
|
|
||||||
try {
|
try {
|
||||||
this.benches.push(await this.time("sqlite-create-table", async () => {
|
|
||||||
console.log("Creating a table...");
|
console.log("Creating a table...");
|
||||||
let res = await this.promiser("exec", {
|
let res = await this.promiser("exec", {
|
||||||
dbId: this.dbId,
|
dbId,
|
||||||
sql: "DROP TABLE IF EXISTS abcdef; CREATE TABLE IF NOT EXISTS abcdef(a,b,c)",
|
sql: "DROP TABLE IF EXISTS abcdef; CREATE TABLE IF NOT EXISTS abcdef(a,b,c)",
|
||||||
returnValue: "resultRows",
|
returnValue: "resultRows",
|
||||||
});
|
});
|
||||||
console.log("Result: ", res);
|
console.log("Result: ", res);
|
||||||
}));
|
|
||||||
|
|
||||||
this.benches.push(
|
|
||||||
await this.time("sqlite-insert-many", async () => {
|
|
||||||
console.log("Insert some data using exec()...");
|
console.log("Insert some data using exec()...");
|
||||||
await this.doInsert(async (i) => {
|
for (let i = 20; i <= 25; ++i) {
|
||||||
let innerRes = await this.promiser("exec", {
|
let innerRes = await this.promiser("exec", {
|
||||||
dbId: this.dbId,
|
dbId,
|
||||||
sql: "INSERT INTO abcdef(a,b,c) VALUES (?,?,69)",
|
sql: "INSERT INTO abcdef(a,b,c) VALUES (?,?,69)",
|
||||||
bind: [i, i * 2],
|
bind: [i, i * 2],
|
||||||
returnValue: "resultRows",
|
returnValue: "resultRows",
|
||||||
rowMode: "object",
|
rowMode: "object",
|
||||||
});
|
});
|
||||||
// console.log(innerRes);
|
console.log(innerRes);
|
||||||
});
|
}
|
||||||
})
|
|
||||||
);
|
|
||||||
this.benches.push(
|
|
||||||
await this.time("sqlite-query-many", async () => {
|
|
||||||
console.log("Query data with exec()...");
|
console.log("Query data with exec()...");
|
||||||
let rowRes = await this.promiser("exec", {
|
let rowRes = await this.promiser("exec", {
|
||||||
dbId: this.dbId,
|
dbId,
|
||||||
sql: "SELECT * FROM abcdef ORDER BY a LIMIT 50",
|
sql: "SELECT * FROM abcdef ORDER BY a LIMIT 10",
|
||||||
returnValue: "resultRows",
|
returnValue: "resultRows",
|
||||||
rowMode: "object",
|
rowMode: "object",
|
||||||
});
|
});
|
||||||
console.log(rowRes);
|
console.log(rowRes);
|
||||||
})
|
|
||||||
);
|
|
||||||
} finally {
|
} 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)
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
19
yarn.lock
19
yarn.lock
@ -576,11 +576,6 @@ ignore@^5.2.0:
|
|||||||
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.1.tgz#5073e554cd42c5b33b394375f538b8593e34d4ef"
|
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.1.tgz#5073e554cd42c5b33b394375f538b8593e34d4ef"
|
||||||
integrity sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==
|
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:
|
is-extglob@^2.1.1:
|
||||||
version "2.1.1"
|
version "2.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"
|
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"
|
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
|
||||||
integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==
|
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:
|
locate-path@^5.0.0:
|
||||||
version "5.0.0"
|
version "5.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0"
|
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0"
|
||||||
|
Loading…
Reference in New Issue
Block a user