Skip to content
This repository has been archived by the owner on Dec 13, 2019. It is now read-only.

[repo] Investigate why extended key path derivation is slow #778

Closed
snario opened this issue Feb 18, 2019 · 10 comments
Closed

[repo] Investigate why extended key path derivation is slow #778

snario opened this issue Feb 18, 2019 · 10 comments
Assignees
Labels

Comments

@snario
Copy link
Contributor

snario commented Feb 18, 2019

Naive profiling reveals that deriving paths from an extended key is slow and takes up a significant amount of time. We should investigate ways to improve this. cc @IIIIllllIIIIllllIIIIllllIIIIllllIIIIll @ricmoo

@ricmoo
Copy link

ricmoo commented Feb 18, 2019

What path does the extended key represent and what path is being derived?

Node or browser? Sha2-512 is not very performant, but I’m planning on making v5 use the crypto version for node.

How slow?

@ldct
Copy link
Member

ldct commented Feb 19, 2019

A quick sample: fromExtendedKey("xpub6E7BR59KtqbeZg98VGEBAtgBb6MPw3xsVnF9TQQyRpFBerY4LJvotYajhT9UFEHB78Q1BCZQATNGi5A3FhJZxRMcwo3mwpJyRp6NePvEoFo").derivePath("0") took 0.189s

@ricmoo
Copy link

ricmoo commented Feb 19, 2019

Browser or node?

@ldct
Copy link
Member

ldct commented Feb 19, 2019

node :)

@snario snario added ⚡️ Performance Tasks related to increasing performance 🔑 Crypto-Related labels Feb 26, 2019
@snario
Copy link
Contributor Author

snario commented Mar 25, 2019

@IIIIllllIIIIllllIIIIllllIIIIllllIIIIll can you detail some ideas on improvements?

@ricmoo
Copy link

ricmoo commented Mar 25, 2019

What platform are you using? Running your exact code above I get it completing in 23ms (0.023s). What platform are you on? Is it a TravisCI instance, which is highly virtualized? What is the output of console.log(ethers.platform)? How are you timing it?

@ldct
Copy link
Member

ldct commented Mar 28, 2019

So apparently this only happens under jest. Really not sure where the bug lies.

Minimum setup to reproduce: https://github.com/IIIIllllIIIIllllIIIIllllIIIIllllIIIIll/jest-ethers-bug

@ldct
Copy link
Member

ldct commented Mar 28, 2019

Maybe related: jestjs/jest#5163 (comment)

@snario snario changed the title Extended key path derivation is slow [repo] Investigate why extended key path derivation is slow Mar 30, 2019
@ldct
Copy link
Member

ldct commented Mar 31, 2019

Fixed by #1187

@ricmoo : not sure if this is within the scope of ethers, but maybe there's a way of detecting if the key derivation function is run under a VM (https://nodejs.org/api/vm.html) and warning that it will be very slow?

@ldct ldct closed this as completed Mar 31, 2019
@ricmoo
Copy link

ricmoo commented Mar 31, 2019

Definitely out of ethers scope. :p

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants