pluresdb 1.0.1 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -5
- package/dist/.tsbuildinfo +1 -1
- package/dist/better-sqlite3-shared.d.ts +12 -0
- package/dist/better-sqlite3-shared.d.ts.map +1 -0
- package/dist/better-sqlite3-shared.js +143 -0
- package/dist/better-sqlite3-shared.js.map +1 -0
- package/dist/better-sqlite3.d.ts +4 -0
- package/dist/better-sqlite3.d.ts.map +1 -0
- package/dist/better-sqlite3.js +8 -0
- package/dist/better-sqlite3.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +21 -16
- package/dist/cli.js.map +1 -1
- package/dist/node-index.d.ts +98 -2
- package/dist/node-index.d.ts.map +1 -1
- package/dist/node-index.js +312 -6
- package/dist/node-index.js.map +1 -1
- package/dist/node-wrapper.d.ts.map +1 -1
- package/dist/node-wrapper.js +5 -3
- package/dist/node-wrapper.js.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/node-types.d.ts +12 -0
- package/dist/types/node-types.d.ts.map +1 -1
- package/dist/types/node-types.js.map +1 -1
- package/dist/vscode/extension.d.ts.map +1 -1
- package/dist/vscode/extension.js +4 -4
- package/dist/vscode/extension.js.map +1 -1
- package/examples/basic-usage.d.ts +1 -1
- package/examples/vscode-extension-example/src/extension.ts +15 -6
- package/examples/vscode-extension-integration.d.ts +24 -17
- package/examples/vscode-extension-integration.js +140 -106
- package/examples/vscode-extension-integration.ts +1 -1
- package/{src → legacy}/benchmarks/memory-benchmarks.ts +85 -51
- package/{src → legacy}/benchmarks/run-benchmarks.ts +32 -10
- package/legacy/better-sqlite3-shared.ts +157 -0
- package/legacy/better-sqlite3.ts +4 -0
- package/{src → legacy}/cli.ts +14 -4
- package/{src → legacy}/config.ts +2 -1
- package/{src → legacy}/core/crdt.ts +4 -1
- package/{src → legacy}/core/database.ts +57 -22
- package/{src → legacy}/healthcheck.ts +11 -5
- package/{src → legacy}/http/api-server.ts +125 -21
- package/{src → legacy}/index.ts +2 -2
- package/{src → legacy}/logic/rules.ts +3 -1
- package/{src → legacy}/main.ts +11 -4
- package/legacy/node-index.ts +823 -0
- package/{src → legacy}/node-wrapper.ts +18 -9
- package/{src → legacy}/sqlite-compat.ts +63 -16
- package/{src → legacy}/sqlite3-compat.ts +2 -2
- package/{src → legacy}/storage/kv-storage.ts +3 -1
- package/{src → legacy}/tests/core.test.ts +37 -13
- package/{src → legacy}/tests/fixtures/test-data.json +6 -1
- package/{src → legacy}/tests/integration/api-server.test.ts +110 -8
- package/{src → legacy}/tests/integration/mesh-network.test.ts +8 -2
- package/{src → legacy}/tests/logic.test.ts +6 -2
- package/{src → legacy}/tests/performance/load.test.ts +4 -2
- package/{src → legacy}/tests/security/input-validation.test.ts +5 -1
- package/{src → legacy}/tests/unit/core.test.ts +13 -3
- package/{src → legacy}/tests/unit/subscriptions.test.ts +1 -1
- package/{src → legacy}/tests/vscode_extension_test.ts +39 -11
- package/{src → legacy}/types/node-types.ts +14 -0
- package/{src → legacy}/vscode/extension.ts +37 -14
- package/package.json +19 -9
- package/scripts/compiled-crud-verify.ts +3 -1
- package/scripts/dogfood.ts +55 -16
- package/scripts/postinstall.js +4 -3
- package/scripts/release-check.js +190 -0
- package/scripts/run-tests.ts +5 -2
- package/scripts/update-changelog.js +214 -0
- package/web/svelte/package.json +5 -5
- package/src/node-index.ts +0 -385
- /package/{src → legacy}/main.rs +0 -0
- /package/{src → legacy}/network/websocket-server.ts +0 -0
- /package/{src → legacy}/tests/fixtures/performance-data.json +0 -0
- /package/{src → legacy}/tests/unit/vector-search.test.ts +0 -0
- /package/{src → legacy}/types/index.ts +0 -0
- /package/{src → legacy}/util/debug.ts +0 -0
- /package/{src → legacy}/vector/index.ts +0 -0
|
@@ -3,44 +3,45 @@
|
|
|
3
3
|
* VSCode Extension Integration Example
|
|
4
4
|
* This shows how to integrate PluresDB into a VSCode extension
|
|
5
5
|
*/
|
|
6
|
-
var __createBinding =
|
|
7
|
-
(this && this.__createBinding) ||
|
|
6
|
+
var __createBinding = (this && this.__createBinding) ||
|
|
8
7
|
(Object.create
|
|
9
8
|
? function (o, m, k, k2) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (
|
|
12
|
+
!desc ||
|
|
13
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
14
|
+
) {
|
|
15
|
+
desc = {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () {
|
|
18
|
+
return m[k];
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
21
|
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}
|
|
22
24
|
: function (o, m, k, k2) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var __setModuleDefault =
|
|
27
|
-
(this && this.__setModuleDefault) ||
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
});
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) ||
|
|
28
29
|
(Object.create
|
|
29
30
|
? function (o, v) {
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
32
|
+
}
|
|
32
33
|
: function (o, v) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var __importStar =
|
|
36
|
-
(this && this.__importStar) ||
|
|
34
|
+
o["default"] = v;
|
|
35
|
+
});
|
|
36
|
+
var __importStar = (this && this.__importStar) ||
|
|
37
37
|
(function () {
|
|
38
38
|
var ownKeys = function (o) {
|
|
39
|
-
ownKeys =
|
|
40
|
-
Object.getOwnPropertyNames ||
|
|
39
|
+
ownKeys = Object.getOwnPropertyNames ||
|
|
41
40
|
function (o) {
|
|
42
41
|
var ar = [];
|
|
43
|
-
for (var k in o)
|
|
42
|
+
for (var k in o) {
|
|
43
|
+
if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
44
|
+
}
|
|
44
45
|
return ar;
|
|
45
46
|
};
|
|
46
47
|
return ownKeys(o);
|
|
@@ -48,9 +49,11 @@ var __importStar =
|
|
|
48
49
|
return function (mod) {
|
|
49
50
|
if (mod && mod.__esModule) return mod;
|
|
50
51
|
var result = {};
|
|
51
|
-
if (mod != null)
|
|
52
|
-
for (var k = ownKeys(mod), i = 0; i < k.length; i++)
|
|
52
|
+
if (mod != null) {
|
|
53
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) {
|
|
53
54
|
if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
54
57
|
__setModuleDefault(result, mod);
|
|
55
58
|
return result;
|
|
56
59
|
};
|
|
@@ -114,7 +117,9 @@ class PluresExtension {
|
|
|
114
117
|
await this.setupDatabase();
|
|
115
118
|
vscode.window.showInformationMessage("PluresDB extension activated");
|
|
116
119
|
} catch (error) {
|
|
117
|
-
vscode.window.showErrorMessage(
|
|
120
|
+
vscode.window.showErrorMessage(
|
|
121
|
+
`Failed to activate PluresDB: ${error.message}`,
|
|
122
|
+
);
|
|
118
123
|
}
|
|
119
124
|
}
|
|
120
125
|
async deactivate() {
|
|
@@ -127,95 +132,124 @@ class PluresExtension {
|
|
|
127
132
|
}
|
|
128
133
|
registerCommands() {
|
|
129
134
|
// Command to open PluresDB web UI
|
|
130
|
-
const openWebUI = vscode.commands.registerCommand(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
const openWebUI = vscode.commands.registerCommand(
|
|
136
|
+
"pluresdb.openWebUI",
|
|
137
|
+
() => {
|
|
138
|
+
const webUrl = this.plures.getWebUrl();
|
|
139
|
+
vscode.env.openExternal(vscode.Uri.parse(webUrl));
|
|
140
|
+
},
|
|
141
|
+
);
|
|
134
142
|
// Command to execute SQL query
|
|
135
|
-
const executeQuery = vscode.commands.registerCommand(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
try {
|
|
142
|
-
const result = await this.sqliteAPI.all(sql);
|
|
143
|
-
const doc = await vscode.workspace.openTextDocument({
|
|
144
|
-
content: JSON.stringify(result, null, 2),
|
|
145
|
-
language: "json",
|
|
146
|
-
});
|
|
147
|
-
await vscode.window.showTextDocument(doc);
|
|
148
|
-
} catch (error) {
|
|
149
|
-
vscode.window.showErrorMessage(`Query failed: ${error.message}`);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
// Command to perform vector search
|
|
154
|
-
const vectorSearch = vscode.commands.registerCommand("pluresdb.vectorSearch", async () => {
|
|
155
|
-
const query = await vscode.window.showInputBox({
|
|
156
|
-
prompt: "Enter search query",
|
|
157
|
-
placeHolder: "machine learning",
|
|
158
|
-
});
|
|
159
|
-
if (query) {
|
|
160
|
-
try {
|
|
161
|
-
const results = await this.sqliteAPI.vectorSearch(query, 10);
|
|
162
|
-
const doc = await vscode.workspace.openTextDocument({
|
|
163
|
-
content: JSON.stringify(results, null, 2),
|
|
164
|
-
language: "json",
|
|
165
|
-
});
|
|
166
|
-
await vscode.window.showTextDocument(doc);
|
|
167
|
-
} catch (error) {
|
|
168
|
-
vscode.window.showErrorMessage(`Vector search failed: ${error.message}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
// Command to store data
|
|
173
|
-
const storeData = vscode.commands.registerCommand("pluresdb.storeData", async () => {
|
|
174
|
-
const key = await vscode.window.showInputBox({
|
|
175
|
-
prompt: "Enter key",
|
|
176
|
-
placeHolder: "user:123",
|
|
177
|
-
});
|
|
178
|
-
if (key) {
|
|
179
|
-
const value = await vscode.window.showInputBox({
|
|
180
|
-
prompt: "Enter value (JSON)",
|
|
181
|
-
placeHolder: '{"name": "John", "email": "john@example.com"}',
|
|
143
|
+
const executeQuery = vscode.commands.registerCommand(
|
|
144
|
+
"pluresdb.executeQuery",
|
|
145
|
+
async () => {
|
|
146
|
+
const sql = await vscode.window.showInputBox({
|
|
147
|
+
prompt: "Enter SQL query",
|
|
148
|
+
placeHolder: "SELECT * FROM users",
|
|
182
149
|
});
|
|
183
|
-
if (
|
|
150
|
+
if (sql) {
|
|
184
151
|
try {
|
|
185
|
-
const
|
|
186
|
-
await
|
|
187
|
-
|
|
152
|
+
const result = await this.sqliteAPI.all(sql);
|
|
153
|
+
const doc = await vscode.workspace.openTextDocument({
|
|
154
|
+
content: JSON.stringify(result, null, 2),
|
|
155
|
+
language: "json",
|
|
156
|
+
});
|
|
157
|
+
await vscode.window.showTextDocument(doc);
|
|
188
158
|
} catch (error) {
|
|
189
|
-
vscode.window.showErrorMessage(`
|
|
159
|
+
vscode.window.showErrorMessage(`Query failed: ${error.message}`);
|
|
190
160
|
}
|
|
191
161
|
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Command to
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
162
|
+
},
|
|
163
|
+
);
|
|
164
|
+
// Command to perform vector search
|
|
165
|
+
const vectorSearch = vscode.commands.registerCommand(
|
|
166
|
+
"pluresdb.vectorSearch",
|
|
167
|
+
async () => {
|
|
168
|
+
const query = await vscode.window.showInputBox({
|
|
169
|
+
prompt: "Enter search query",
|
|
170
|
+
placeHolder: "machine learning",
|
|
171
|
+
});
|
|
172
|
+
if (query) {
|
|
173
|
+
try {
|
|
174
|
+
const results = await this.sqliteAPI.vectorSearch(query, 10);
|
|
204
175
|
const doc = await vscode.workspace.openTextDocument({
|
|
205
|
-
content: JSON.stringify(
|
|
176
|
+
content: JSON.stringify(results, null, 2),
|
|
206
177
|
language: "json",
|
|
207
178
|
});
|
|
208
179
|
await vscode.window.showTextDocument(doc);
|
|
209
|
-
}
|
|
210
|
-
vscode.window.
|
|
180
|
+
} catch (error) {
|
|
181
|
+
vscode.window.showErrorMessage(
|
|
182
|
+
`Vector search failed: ${error.message}`,
|
|
183
|
+
);
|
|
211
184
|
}
|
|
212
|
-
} catch (error) {
|
|
213
|
-
vscode.window.showErrorMessage(`Failed to retrieve data: ${error.message}`);
|
|
214
185
|
}
|
|
215
|
-
}
|
|
216
|
-
|
|
186
|
+
},
|
|
187
|
+
);
|
|
188
|
+
// Command to store data
|
|
189
|
+
const storeData = vscode.commands.registerCommand(
|
|
190
|
+
"pluresdb.storeData",
|
|
191
|
+
async () => {
|
|
192
|
+
const key = await vscode.window.showInputBox({
|
|
193
|
+
prompt: "Enter key",
|
|
194
|
+
placeHolder: "user:123",
|
|
195
|
+
});
|
|
196
|
+
if (key) {
|
|
197
|
+
const value = await vscode.window.showInputBox({
|
|
198
|
+
prompt: "Enter value (JSON)",
|
|
199
|
+
placeHolder: '{"name": "John", "email": "john@example.com"}',
|
|
200
|
+
});
|
|
201
|
+
if (value) {
|
|
202
|
+
try {
|
|
203
|
+
const parsedValue = JSON.parse(value);
|
|
204
|
+
await this.sqliteAPI.put(key, parsedValue);
|
|
205
|
+
vscode.window.showInformationMessage(
|
|
206
|
+
`Stored data for key: ${key}`,
|
|
207
|
+
);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
vscode.window.showErrorMessage(
|
|
210
|
+
`Failed to store data: ${error.message}`,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
);
|
|
217
|
+
// Command to retrieve data
|
|
218
|
+
const retrieveData = vscode.commands.registerCommand(
|
|
219
|
+
"pluresdb.retrieveData",
|
|
220
|
+
async () => {
|
|
221
|
+
const key = await vscode.window.showInputBox({
|
|
222
|
+
prompt: "Enter key to retrieve",
|
|
223
|
+
placeHolder: "user:123",
|
|
224
|
+
});
|
|
225
|
+
if (key) {
|
|
226
|
+
try {
|
|
227
|
+
const value = await this.sqliteAPI.getValue(key);
|
|
228
|
+
if (value) {
|
|
229
|
+
const doc = await vscode.workspace.openTextDocument({
|
|
230
|
+
content: JSON.stringify(value, null, 2),
|
|
231
|
+
language: "json",
|
|
232
|
+
});
|
|
233
|
+
await vscode.window.showTextDocument(doc);
|
|
234
|
+
} else {
|
|
235
|
+
vscode.window.showInformationMessage("Key not found");
|
|
236
|
+
}
|
|
237
|
+
} catch (error) {
|
|
238
|
+
vscode.window.showErrorMessage(
|
|
239
|
+
`Failed to retrieve data: ${error.message}`,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
);
|
|
217
245
|
// Register all commands
|
|
218
|
-
this.context.subscriptions.push(
|
|
246
|
+
this.context.subscriptions.push(
|
|
247
|
+
openWebUI,
|
|
248
|
+
executeQuery,
|
|
249
|
+
vectorSearch,
|
|
250
|
+
storeData,
|
|
251
|
+
retrieveData,
|
|
252
|
+
);
|
|
219
253
|
}
|
|
220
254
|
async setupDatabase() {
|
|
221
255
|
// Create tables for common VSCode extension use cases
|
|
@@ -54,9 +54,13 @@ class MemoryBenchmark {
|
|
|
54
54
|
|
|
55
55
|
this.results.push(metrics);
|
|
56
56
|
|
|
57
|
-
console.log(
|
|
57
|
+
console.log(
|
|
58
|
+
` Initial Memory: ${(initialMemory / 1024 / 1024).toFixed(2)}MB`,
|
|
59
|
+
);
|
|
58
60
|
console.log(` Final Memory: ${(finalMemory / 1024 / 1024).toFixed(2)}MB`);
|
|
59
|
-
console.log(
|
|
61
|
+
console.log(
|
|
62
|
+
` Memory Increase: ${(memoryIncrease / 1024 / 1024).toFixed(2)}MB`,
|
|
63
|
+
);
|
|
60
64
|
console.log(` Memory per Record: ${memoryPerRecord.toFixed(2)} bytes`);
|
|
61
65
|
console.log();
|
|
62
66
|
|
|
@@ -71,8 +75,14 @@ class MemoryBenchmark {
|
|
|
71
75
|
this.results.forEach((result) => {
|
|
72
76
|
console.log(`${result.operation}:`);
|
|
73
77
|
console.log(` Records: ${result.recordCount.toLocaleString()}`);
|
|
74
|
-
console.log(
|
|
75
|
-
|
|
78
|
+
console.log(
|
|
79
|
+
` Memory Increase: ${
|
|
80
|
+
(result.memoryIncrease / 1024 / 1024).toFixed(2)
|
|
81
|
+
}MB`,
|
|
82
|
+
);
|
|
83
|
+
console.log(
|
|
84
|
+
` Memory per Record: ${result.memoryPerRecord.toFixed(2)} bytes`,
|
|
85
|
+
);
|
|
76
86
|
console.log();
|
|
77
87
|
});
|
|
78
88
|
}
|
|
@@ -92,53 +102,69 @@ async function runMemoryBenchmarks() {
|
|
|
92
102
|
console.log("Starting Memory Benchmarks...\n");
|
|
93
103
|
|
|
94
104
|
// Benchmark 1: Small Records
|
|
95
|
-
await benchmark.measureMemoryUsage(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
await benchmark.measureMemoryUsage(
|
|
106
|
+
"Small Records (100 bytes)",
|
|
107
|
+
1000,
|
|
108
|
+
async () => {
|
|
109
|
+
for (let i = 0; i < 1000; i++) {
|
|
110
|
+
await db.put(`small:${i}`, {
|
|
111
|
+
id: i,
|
|
112
|
+
data: "x".repeat(100),
|
|
113
|
+
timestamp: Date.now(),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
);
|
|
104
118
|
|
|
105
119
|
// Benchmark 2: Medium Records
|
|
106
|
-
await benchmark.measureMemoryUsage(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
120
|
+
await benchmark.measureMemoryUsage(
|
|
121
|
+
"Medium Records (1KB)",
|
|
122
|
+
1000,
|
|
123
|
+
async () => {
|
|
124
|
+
for (let i = 0; i < 1000; i++) {
|
|
125
|
+
await db.put(`medium:${i}`, {
|
|
126
|
+
id: i,
|
|
127
|
+
data: "x".repeat(1024),
|
|
128
|
+
timestamp: Date.now(),
|
|
129
|
+
metadata: { size: "medium", type: "test" },
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
);
|
|
116
134
|
|
|
117
135
|
// Benchmark 3: Large Records
|
|
118
|
-
await benchmark.measureMemoryUsage(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
136
|
+
await benchmark.measureMemoryUsage(
|
|
137
|
+
"Large Records (10KB)",
|
|
138
|
+
100,
|
|
139
|
+
async () => {
|
|
140
|
+
for (let i = 0; i < 100; i++) {
|
|
141
|
+
await db.put(`large:${i}`, {
|
|
142
|
+
id: i,
|
|
143
|
+
data: "x".repeat(10 * 1024),
|
|
144
|
+
timestamp: Date.now(),
|
|
145
|
+
metadata: { size: "large", type: "test" },
|
|
146
|
+
additional: "y".repeat(1024),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
);
|
|
129
151
|
|
|
130
152
|
// Benchmark 4: Vector Data
|
|
131
|
-
await benchmark.measureMemoryUsage(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
vector
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
153
|
+
await benchmark.measureMemoryUsage(
|
|
154
|
+
"Vector Data (100 dimensions)",
|
|
155
|
+
500,
|
|
156
|
+
async () => {
|
|
157
|
+
for (let i = 0; i < 500; i++) {
|
|
158
|
+
const vector = Array.from({ length: 100 }, () => Math.random());
|
|
159
|
+
await db.put(`vector:${i}`, {
|
|
160
|
+
id: i,
|
|
161
|
+
text: `Document ${i} with vector data`,
|
|
162
|
+
vector: vector,
|
|
163
|
+
timestamp: Date.now(),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
);
|
|
142
168
|
|
|
143
169
|
// Benchmark 5: Nested Objects
|
|
144
170
|
await benchmark.measureMemoryUsage("Nested Objects", 500, async () => {
|
|
@@ -181,9 +207,9 @@ async function runMemoryBenchmarks() {
|
|
|
181
207
|
|
|
182
208
|
// Clean up subscriptions
|
|
183
209
|
if ((globalThis as any).subscriptions) {
|
|
184
|
-
((globalThis as any).subscriptions as Array<() => void>).forEach((
|
|
185
|
-
unsubscribe
|
|
186
|
-
);
|
|
210
|
+
((globalThis as any).subscriptions as Array<() => void>).forEach((
|
|
211
|
+
unsubscribe,
|
|
212
|
+
) => unsubscribe());
|
|
187
213
|
delete (globalThis as any).subscriptions;
|
|
188
214
|
}
|
|
189
215
|
|
|
@@ -251,7 +277,9 @@ async function runMemoryLeakTests() {
|
|
|
251
277
|
const memoryIncrease = finalMemory - initialMemory;
|
|
252
278
|
|
|
253
279
|
console.log(
|
|
254
|
-
`Memory increase after subscription cycles: ${
|
|
280
|
+
`Memory increase after subscription cycles: ${
|
|
281
|
+
(memoryIncrease / 1024).toFixed(2)
|
|
282
|
+
}KB`,
|
|
255
283
|
);
|
|
256
284
|
|
|
257
285
|
if (memoryIncrease > 1024 * 1024) {
|
|
@@ -269,7 +297,9 @@ async function runMemoryLeakTests() {
|
|
|
269
297
|
// Perform many CRUD operations
|
|
270
298
|
for (let cycle = 0; cycle < 100; cycle++) {
|
|
271
299
|
for (let i = 0; i < 100; i++) {
|
|
272
|
-
await db.put(`leak:${cycle}:${i}`, {
|
|
300
|
+
await db.put(`leak:${cycle}:${i}`, {
|
|
301
|
+
data: `Cycle ${cycle} Item ${i}`,
|
|
302
|
+
});
|
|
273
303
|
await db.get(`leak:${cycle}:${i}`);
|
|
274
304
|
await db.delete(`leak:${cycle}:${i}`);
|
|
275
305
|
}
|
|
@@ -283,7 +313,11 @@ async function runMemoryLeakTests() {
|
|
|
283
313
|
const crudFinalMemory = (performance as any).memory?.usedJSHeapSize || 0;
|
|
284
314
|
const crudMemoryIncrease = crudFinalMemory - crudInitialMemory;
|
|
285
315
|
|
|
286
|
-
console.log(
|
|
316
|
+
console.log(
|
|
317
|
+
`Memory increase after CRUD cycles: ${
|
|
318
|
+
(crudMemoryIncrease / 1024).toFixed(2)
|
|
319
|
+
}KB`,
|
|
320
|
+
);
|
|
287
321
|
|
|
288
322
|
if (crudMemoryIncrease > 1024 * 1024) {
|
|
289
323
|
// More than 1MB
|
|
@@ -46,7 +46,11 @@ class BenchmarkRunner {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
this.results.push(result);
|
|
49
|
-
console.log(
|
|
49
|
+
console.log(
|
|
50
|
+
` ✓ ${operationsPerSecond.toFixed(2)} ops/sec (${
|
|
51
|
+
averageTime.toFixed(2)
|
|
52
|
+
}ms avg)`,
|
|
53
|
+
);
|
|
50
54
|
|
|
51
55
|
return result;
|
|
52
56
|
}
|
|
@@ -63,7 +67,9 @@ class BenchmarkRunner {
|
|
|
63
67
|
console.log(` Average Time: ${result.averageTime.toFixed(2)}ms`);
|
|
64
68
|
console.log(` Operations/sec: ${result.operationsPerSecond.toFixed(2)}`);
|
|
65
69
|
if (result.memoryUsage) {
|
|
66
|
-
console.log(
|
|
70
|
+
console.log(
|
|
71
|
+
` Memory Usage: ${(result.memoryUsage / 1024 / 1024).toFixed(2)}MB`,
|
|
72
|
+
);
|
|
67
73
|
}
|
|
68
74
|
console.log();
|
|
69
75
|
});
|
|
@@ -117,8 +123,10 @@ async function runCoreBenchmarks() {
|
|
|
117
123
|
// First populate with documents
|
|
118
124
|
for (let i = 0; i < 100; i++) {
|
|
119
125
|
await db.put(`doc:${i}`, {
|
|
120
|
-
text:
|
|
121
|
-
|
|
126
|
+
text:
|
|
127
|
+
`Document ${i} about machine learning and artificial intelligence`,
|
|
128
|
+
content:
|
|
129
|
+
`This is document number ${i} containing information about AI and ML algorithms`,
|
|
122
130
|
});
|
|
123
131
|
}
|
|
124
132
|
|
|
@@ -244,8 +252,14 @@ async function runMemoryBenchmarks() {
|
|
|
244
252
|
const finalMemory = (performance as any).memory?.usedJSHeapSize || 0;
|
|
245
253
|
const memoryIncrease = finalMemory - initialMemory;
|
|
246
254
|
|
|
247
|
-
console.log(
|
|
248
|
-
|
|
255
|
+
console.log(
|
|
256
|
+
`Memory Usage: ${
|
|
257
|
+
(memoryIncrease / 1024 / 1024).toFixed(2)
|
|
258
|
+
}MB for 1000 records`,
|
|
259
|
+
);
|
|
260
|
+
console.log(
|
|
261
|
+
`Memory per record: ${(memoryIncrease / 1000).toFixed(2)} bytes`,
|
|
262
|
+
);
|
|
249
263
|
|
|
250
264
|
// Benchmark 2: Subscription Memory Usage
|
|
251
265
|
const subscriptionMemory = (performance as any).memory?.usedJSHeapSize || 0;
|
|
@@ -257,13 +271,21 @@ async function runMemoryBenchmarks() {
|
|
|
257
271
|
subscriptions.push(unsubscribe);
|
|
258
272
|
});
|
|
259
273
|
|
|
260
|
-
const afterSubscriptionMemory =
|
|
261
|
-
|
|
274
|
+
const afterSubscriptionMemory =
|
|
275
|
+
(performance as any).memory?.usedJSHeapSize || 0;
|
|
276
|
+
const subscriptionMemoryIncrease = afterSubscriptionMemory -
|
|
277
|
+
subscriptionMemory;
|
|
262
278
|
|
|
263
279
|
console.log(
|
|
264
|
-
`Subscription Memory: ${
|
|
280
|
+
`Subscription Memory: ${
|
|
281
|
+
(subscriptionMemoryIncrease / 1024).toFixed(2)
|
|
282
|
+
}KB for 1000 subscriptions`,
|
|
283
|
+
);
|
|
284
|
+
console.log(
|
|
285
|
+
`Memory per subscription: ${
|
|
286
|
+
(subscriptionMemoryIncrease / 1000).toFixed(2)
|
|
287
|
+
} bytes`,
|
|
265
288
|
);
|
|
266
|
-
console.log(`Memory per subscription: ${(subscriptionMemoryIncrease / 1000).toFixed(2)} bytes`);
|
|
267
289
|
|
|
268
290
|
// Clean up subscriptions
|
|
269
291
|
subscriptions.forEach((unsubscribe) => unsubscribe());
|