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

Cache MAC address to speed up uuid1/0 #45

Closed
wants to merge 1 commit into from
Closed

Cache MAC address to speed up uuid1/0 #45

wants to merge 1 commit into from

Conversation

whatyouhide
Copy link
Contributor

Closes #40.

Getting the MAC address (through :inet.getifaddrs/0) is slow, resulting in the uuid1/0 function being around 100x slower than the other UUID functions. With this commit we're starting up a GenServer that caches the MAC address in :persistent_term if available or ETS otherwise. This GenServer refreshes the MAC address every 10 seconds.

Benchmark before:

## UUIDBench
benchmark name     iterations   average time 
binary_to_string!     1000000   1.17 µs/op
uuid3 dns             1000000   1.48 µs/op
uuid5 dns             1000000   1.67 µs/op
uuid4                 1000000   2.10 µs/op
string_to_binary!     1000000   2.98 µs/op
info!                  500000   3.18 µs/op
uuid1                   10000   218.52 µs/op

Benchmark after:

## UUIDBench
benchmark name     iterations   average time 
binary_to_string!     1000000   1.15 µs/op
uuid3 dns             1000000   1.48 µs/op
uuid5 dns             1000000   1.56 µs/op
uuid4                 1000000   2.03 µs/op
uuid1                 1000000   2.21 µs/op
info!                 1000000   2.97 µs/op
string_to_binary!     1000000   3.00 µs/op

cc @zyro, sorry it took a few months to get to this 😄

Closes #40.

Getting the MAC address (through :inet.getifaddrs/0) is slow, resulting
in the uuid1/0 function being around 100x slower than the other UUID
functions. With this commit we're starting up a GenServer that caches
the MAC address in :persistent_term if available or ETS otherwise.
This GenServer refreshes the MAC address every 10 seconds.
@relistan
Copy link

🥇 This will be great.

@whatyouhide
Copy link
Contributor Author

Ping @zyro! :bowtie:

@whatyouhide
Copy link
Contributor Author

Closing this one for inactivity. @zyro if you ever get to it, hit me up and I'll make sure to reopen it :) Thanks!

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

Successfully merging this pull request may close these issues.

uuid1/0 is slow because it gets the MAC address every time
2 participants