r-lyeh-archived/sole

Better performance for uuid4

Closed this issue · 4 comments

I was doing some performance profiling and it seems that sole is the slowest bit in our code.

I notice the code is just doing:

std::random_device rd;
std::uniform_int_distribution<uint64_t> dist(0, (uint64_t)(~0));

The performance was better when I added static:

static std::random_device rd;
static std::uniform_int_distribution<uint64_t> dist(0, (uint64_t)(~0));

Not sure if there is any side effects but seems to work fine for us.

I can confirm this leads to a 2x performance improvement on my machine.
Tests seem to run fine (no collisions etc...).

Note that making the uniform static seems like overkill, does not change performance in any significant manner...

Ah good. Yeah, it tested fine with everything I threw at it. It hasn't broken anything in our app so far :)

and then maybe clang will complain at-exit destructors once again some day (#13)!
fingers crossed! xD