nanocurrency-js icon indicating copy to clipboard operation
nanocurrency-js copied to clipboard

Slow performance with derivePublicKey(secretKey)

Open Joohansson opened this issue 4 years ago • 4 comments

I'm building a reactJS app for finding vanity addresses using this library and web workers to get multithreading. It all works great and the following code does the address creation and matching. However I have problem with performance. Without the derivePublicKey below I can do 150,000 loops per second. With the derivePublicKey the performance drops to 600/s. Another strange thing is that there is no difference using 2 threads or 12 when doing that. Just using "currentAddressesCount += 1" boost the loop count to 120 million per second so nothing wrong with the multithreading implementation. Perhaps there is nothing wrong with your library but maybe you know what's wrong?

function search() {
  currentAddressesCount += 1
  const array = new Uint8Array(32)
  // eslint-disable-next-line no-restricted-globals
  self.crypto.getRandomValues(array)
  const seed = array.reduce((hex, idx) => hex + (`0${idx.toString(16)}`).slice(-2), '')
  const secretKey = nano.deriveSecretKey(seed, 0)
  const publicKey = nano.derivePublicKey(secretKey)
  const address = nano.deriveAddress(publicKey, {useNanoPrefix: true})

  if (isMatch(address)) {
    postMessage(address)
  }
}

Joohansson avatar Dec 24 '19 08:12 Joohansson

Testing this tool https://github.com/vitorcremonez/nano-vanity I have now verified that running [email protected] with await nanocurrency.init() indeed result in 10,000 keys/s per thread compared to 300/s per thread with [email protected] which has no init() function. Easy to test by doing npm install and jumping between the two versions. So something has changed with this library. I hope it can be solved somehow.

Also tested with my own multithreading script and getting 70-120k per sec using 12 threads, with 1.7.4.

Joohansson avatar Dec 25 '19 07:12 Joohansson

Ok, looks like the issue has been tracked down. https://github.com/marvinroger/nanocurrency-js/issues/24

You never did the high performance deriveAddressFromSeed function, right? I'm currently in need of high performance key derivation when multi-creating wallets, mass extracting keys/addresses from one seed, searching for a particular address in a seed and vanity address searches. Currently solved by using both the 1.7.4 and 2.3.0 in parallel.

Joohansson avatar Dec 29 '19 07:12 Joohansson

I would also like the function! @marvinroger

bbaraban avatar May 27 '21 00:05 bbaraban

I'm currently working on it, I'll add new optimized WASM functions

marvinroger avatar May 29 '21 14:05 marvinroger