Files
bitvid/benchmarks/reaction_loading_bench.mjs
T
google-labs-jules[bot]andPR0M3TH3AN 2b061460eb perf: limit reaction event concurrency
Weekly perf deep dive:
- Replaced unbounded `Promise.all` in `js/nostr/reactionEvents.js` with `pMap` limited to `RELAY_BACKGROUND_CONCURRENCY` (3).
- Added `benchmarks/reaction_loading_bench.mjs` harness to verify concurrency limits.
- Added weekly perf report in `docs/perf-reports/weekly-perf-report-2026-02-13.md`.
- Added completion log.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-13 22:09:30 +00:00

51 lines
1.4 KiB
JavaScript

import { listVideoReactions } from '../js/nostr/reactionEvents.js';
import { RELAY_BACKGROUND_CONCURRENCY } from '../js/nostr/relayConstants.js';
const NUM_RELAYS = 20;
const DELAY_MS = 100;
const mockRelays = Array.from({ length: NUM_RELAYS }, (_, i) => `wss://mock-relay-${i}.com`);
let activeRequests = 0;
let peakRequests = 0;
const mockPool = {
list: async (relays, filters) => {
activeRequests++;
if (activeRequests > peakRequests) {
peakRequests = activeRequests;
}
// Simulate network delay
await new Promise(resolve => setTimeout(resolve, DELAY_MS));
activeRequests--;
return []; // Return empty events for now
}
};
const mockClient = {
pool: mockPool,
relays: mockRelays, // Allow these relays
ensurePool: async () => mockPool
};
async function runBenchmark() {
console.log(`Starting benchmark with ${NUM_RELAYS} relays...`);
console.log(`Expected concurrency limit (after fix): ${RELAY_BACKGROUND_CONCURRENCY}`);
const start = performance.now();
await listVideoReactions(mockClient, { id: 'test-video-id' }, { relays: mockRelays });
const end = performance.now();
console.log('---------------------------------------------------');
console.log(`Total time: ${(end - start).toFixed(2)}ms`);
console.log(`Peak concurrent requests: ${peakRequests}`);
console.log('---------------------------------------------------');
}
runBenchmark().catch(console.error);