Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: improve vanity address matching #3219

Merged
merged 1 commit into from Sep 15, 2022

Conversation

mattsse
Copy link
Member

@mattsse mattsse commented Sep 15, 2022

Motivation

the previous impl was a regex match on the address in hex format, which required additional allocs

Solution

this will try to match against the address bytes directly if the (start, end) are valid hex,
this means however, that odd patterns are still parsed via regex. this is probably faster for longer patterns than left|right padding

it accepts all combinations of --starts-with (hex|regex) --ends-with (hex|regex)

Example

cast wallet vanity --starts-with "0000"                                                                                                                                                         
Starting to generate vanity address...
Successfully found vanity address in 10 seconds.
Address: 0x00009AaB527c82E0ac9B53EB83DbBdd87aDeff14
Private Key: 0x637cbf8de182f697447b06bb2de563584b04b346500d140dbd25dc2d223366c1

@mattsse mattsse added C-cast Command: cast T-perf Type: performance labels Sep 15, 2022
@gakonst
Copy link
Member

gakonst commented Sep 15, 2022

was this a meaningful perf improvement?

@mattsse
Copy link
Member Author

mattsse commented Sep 15, 2022

hard to say, since the iterator always uses a new random key, but matching by comparing bytes of the address directly instead of comparing the allocated string via regex is definitely faster

@gakonst gakonst merged commit e7a4e3b into foundry-rs:master Sep 15, 2022
iFrostizz pushed a commit to iFrostizz/foundry that referenced this pull request Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cast Command: cast T-perf Type: performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants