From 1951eb32a249723778650bbf953628bc45220693 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sat, 30 Nov 2024 22:06:29 -0800 Subject: [PATCH] Add a few logs for perf testing. --- src/lib/pool.ts | 5 +++-- src/lib/wallet.ts | 2 -- src/lib/workers/ckdBip44.ts | 1 + src/lib/workers/nano-nacl.ts | 8 ++++++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/lib/pool.ts b/src/lib/pool.ts index e664720..edb5b37 100644 --- a/src/lib/pool.ts +++ b/src/lib/pool.ts @@ -34,7 +34,6 @@ export class Pool { } constructor (fn: string) { - console.log(`cores: ${this.#cores}`) const url = URL.createObjectURL(new Blob([fn], { type: 'text/javascript' })) for (let i = this.#cores; i > 0; i--) { const thread = { @@ -43,6 +42,7 @@ export class Pool { worker: new Worker(url, { type: 'module', eval: true }) } thread.worker.addEventListener('message', (message) => { + console.log(`received worker response (${performance.now()})`) let result = JSON.parse(new TextDecoder().decode(message.data ?? message)) if (!Array.isArray(result)) result = [result] this.#report(thread, result) @@ -55,7 +55,7 @@ export class Pool { if (next.length > 0) { thread.isBusy = true const buf = new TextEncoder().encode(JSON.stringify(next)).buffer - console.log(`posting to ${thread} (${performance.now()})`) + console.log(`posting to thread (${performance.now()})`) thread.worker.postMessage(buf, [buf]) } } @@ -71,6 +71,7 @@ export class Pool { } async work (data: object[]): Promise { + console.log(`pool.work (${performance.now()})`) if (!Array.isArray(data)) data = [data] return new Promise(resolve => { this.#queue = data diff --git a/src/lib/wallet.ts b/src/lib/wallet.ts index 398c477..2ddca76 100644 --- a/src/lib/wallet.ts +++ b/src/lib/wallet.ts @@ -98,8 +98,6 @@ abstract class Wallet { let results = await this.ckd(indexes) const data: any = [] results.forEach(r => data.push({ privateKey: r.privateKey, index: r.index })) - console.log(`accounts data`) - console.dir(data) let now = performance.now() const keypairs: KeyPair[] = await this.#pool.work(data) console.log(`keypairs: ${-now + (now = performance.now())} ms`) diff --git a/src/lib/workers/ckdBip44.ts b/src/lib/workers/ckdBip44.ts index 99a8ed8..c1f1294 100644 --- a/src/lib/workers/ckdBip44.ts +++ b/src/lib/workers/ckdBip44.ts @@ -16,6 +16,7 @@ const Bip44Ckd = () => { * Listens for messages from a calling function. */ addEventListener('message', (message) => { + console.log(`bip44ckd work received (${performance.now()})`) const data = JSON.parse(new TextDecoder().decode(message.data ?? message)) process(data).then(results => { const buf = new TextEncoder().encode(JSON.stringify(results)).buffer diff --git a/src/lib/workers/nano-nacl.ts b/src/lib/workers/nano-nacl.ts index 3cea4a0..deeb9ec 100644 --- a/src/lib/workers/nano-nacl.ts +++ b/src/lib/workers/nano-nacl.ts @@ -20,12 +20,16 @@ const NanoNaCl = () => { * Listens for messages from a calling function. */ addEventListener('message', (message) => { + console.log(`nacl work received (${performance.now()})`) const data = JSON.parse(new TextDecoder().decode(message.data ?? message)) - for (const d of data) { - d.publicKey = hexify(keyPair(d.privateKey).publicKey) + // for (const d of data) { + for (let i = 0; i < data.length; i++) { + if (i % 100 === 0) console.log(`${i} keys`) + data[i].publicKey = hexify(keyPair(data[i].privateKey).publicKey) } const buf = new TextEncoder().encode(JSON.stringify(data)).buffer //@ts-expect-error + console.log(`nacl work done (${performance.now()})`) postMessage(buf, [buf]) }) -- 2.34.1