mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Limits the O(N^2) pairwise check in `normalizeNip46CiphertextPayload` to small arrays (<= 16 items) to prevent combinatorial explosion. This heuristic is only intended for small split-payload cases, and processing large arrays this way was unnecessary and caused performance issues. Benchmark results (200 items, 100 iterations): - Before: ~54.84ms per iteration - After: ~0.12ms per iteration - Improvement: ~457x speedup Co-authored-by: PR0M3TH3AN <[email protected]>
29 lines
786 B
JavaScript
29 lines
786 B
JavaScript
|
|
import { normalizeNip46CiphertextPayload } from "../js/nostr/nip46Client.js";
|
|
|
|
const ITERATIONS = 100;
|
|
const ARRAY_SIZE = 200;
|
|
|
|
function runBenchmark() {
|
|
const largeArray = Array.from({ length: ARRAY_SIZE }, (_, i) => `string_${i}`);
|
|
|
|
// Wrap in a structure that triggers the recursive coerce and then the array handling
|
|
const payload = {
|
|
data: largeArray
|
|
};
|
|
|
|
const start = performance.now();
|
|
|
|
for (let i = 0; i < ITERATIONS; i++) {
|
|
normalizeNip46CiphertextPayload(payload);
|
|
}
|
|
|
|
const end = performance.now();
|
|
const duration = end - start;
|
|
|
|
console.log(`Time taken for ${ITERATIONS} iterations with array size ${ARRAY_SIZE}: ${duration.toFixed(2)}ms`);
|
|
console.log(`Average time per iteration: ${(duration / ITERATIONS).toFixed(2)}ms`);
|
|
}
|
|
|
|
runBenchmark();
|