mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
feat(perf): accelerate load test signing with WASM
Replaces pure JS `finalizeEvent` with `nostr-tools/wasm` implementation in `scripts/agent/load-test.mjs`. This reduces signing time from ~6ms to ~1ms per event (5x-6x speedup), significantly increasing the event generation throughput capacity of the load test agent. - Adds `nostr-wasm` to devDependencies. - Updates `scripts/agent/load-test.mjs` to initialize and use WASM crypto. - Adds `benchmarks/signing_benchmark.mjs` to verify performance gains. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
74d15f2946
commit
1569ce074f
4 files changed
+99
-26
No files matched your search
@@ -1,11 +1,16 @@
|
||||
import { WebSocket } from 'ws';
|
||||
import { finalizeEvent, generateSecretKey, getPublicKey } from 'nostr-tools';
|
||||
import { finalizeEvent as pureFinalize, generateSecretKey, getPublicKey as pureGetPublicKey } from 'nostr-tools';
|
||||
import { finalizeEvent as wasmFinalize, getPublicKey as wasmGetPublicKey, setNostrWasm } from 'nostr-tools/wasm';
|
||||
import { initNostrWasm } from 'nostr-wasm';
|
||||
import { startRelay } from './simple-relay.mjs';
|
||||
import { buildViewEvent, buildVideoPostEvent } from '../../js/nostrEventSchemas.js';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
let finalizeEvent = pureFinalize;
|
||||
let getPublicKey = pureGetPublicKey;
|
||||
|
||||
// --- Polyfills and Environment Setup ---
|
||||
if (typeof global.window === 'undefined') {
|
||||
global.window = {};
|
||||
@@ -223,6 +228,17 @@ class LoadClient {
|
||||
async function main() {
|
||||
console.log(`Starting load test with config:`, config);
|
||||
|
||||
try {
|
||||
console.log('Initializing WASM crypto...');
|
||||
const wasm = await initNostrWasm();
|
||||
setNostrWasm(wasm);
|
||||
finalizeEvent = wasmFinalize;
|
||||
getPublicKey = wasmGetPublicKey;
|
||||
console.log('WASM crypto initialized successfully.');
|
||||
} catch (error) {
|
||||
console.warn('Failed to initialize WASM crypto, falling back to pure JS:', error);
|
||||
}
|
||||
|
||||
let relayServer;
|
||||
let relayUrl = config.relay;
|
||||
|
||||
@@ -358,11 +374,13 @@ function generateReport() {
|
||||
report.topHotFunctions.push({
|
||||
function: "finalizeEvent (client signing)",
|
||||
avgTime: `${avgSignTime.toFixed(2)}ms`,
|
||||
impact: avgSignTime > 10 ? "High CPU usage" : "Moderate CPU usage"
|
||||
impact: avgSignTime > 10 ? "High CPU usage" : "Low/Moderate CPU usage"
|
||||
});
|
||||
|
||||
if (avgSignTime > 10) {
|
||||
report.proposedRemediation.push("Use optimized crypto library (e.g. secp256k1-wasm) or offload signing to a worker/signer.");
|
||||
} else {
|
||||
report.proposedRemediation.push("Signing speed is good (<10ms). Focus on network I/O.");
|
||||
}
|
||||
|
||||
if (p99 > 1000) {
|
||||
@@ -393,6 +411,7 @@ function generateReport() {
|
||||
console.log(` Latency p50: ${p50}ms`);
|
||||
console.log(` Latency p95: ${p95}ms`);
|
||||
console.log(` Errors: ${stats.errors}`);
|
||||
console.log(` Avg Signing Time: ${avgSignTime.toFixed(2)}ms`);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
Reference in new issue
Block a user