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 theuuid1/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:
Benchmark after:
cc @zyro, sorry it took a few months to get to this 😄