Topic: UUID and perf

Hi,

from a discussion about UUID perf here:
https://dev.to/fredbouchery/performance-des-uuids-29dj
sorry in french wink

I have rewritten `uuid_parse` and uuid_unparse
This brings a better performance, mainly for uuid_unparse.
May I propose the change although it will not use uuid parse and unparse implementation from the distribution ?

For example unparse will use something like

char const __str_digits_lower[36] = "0123456789abcdefghijklmnopqrstuvwxyz";


static void __uuid_fmt(char buf[UUID_STRING_LEN + 1], const uuid_t uuid)
{
    char *p = buf;

    for (int i = 0; i < 16; i++) {
        if (i == 4 || i == 6 || i == 8 || i == 10) {
            *p++ = '-';
        }
        *p++ = __str_digits_lower[uuid[i] >> 4];
        *p++ = __str_digits_lower[uuid[i] & 15];
    }
    *p = '\0';
}

Re: UUID and perf

the uuid extension is a simple binding on the libuuid, and it will be very strange to use an alternative implementation.

BTW, I think your too much simple code may only work on little endian, this really need to be tested

Desktop: Fedora 31 x86_64 + rpmfusion + remi-test + remi-dev
Laptop:  Fedora 30 x86_64 + rpmfusion + remi (SCL only)
Hosting Server: CentOS 6.10 x86_64 with EPEL, remi, remi-php72 and remi-php72-test

Re: UUID and perf

So, I mean, if code may be optimized, this have to be done in upstream (util-linux)

Desktop: Fedora 31 x86_64 + rpmfusion + remi-test + remi-dev
Laptop:  Fedora 30 x86_64 + rpmfusion + remi (SCL only)
Hosting Server: CentOS 6.10 x86_64 with EPEL, remi, remi-php72 and remi-php72-test

Re: UUID and perf

For fun, I run a small test
=> https://github.com/php/pecl-networking- … st_unparse

Honestly, 40ms vs 5ms, yes it is faster
but 40ms for 100 000 calls... 0.4µs per call...

Desktop: Fedora 31 x86_64 + rpmfusion + remi-test + remi-dev
Laptop:  Fedora 30 x86_64 + rpmfusion + remi (SCL only)
Hosting Server: CentOS 6.10 x86_64 with EPEL, remi, remi-php72 and remi-php72-test

Re: UUID and perf

For microservices using one or more uuid on each call, the difference is visible.
I have done the patch on util-linux/libuuid

https://github.com/utix/util-linux/tree/uuid-perf

For 1 million uuid_unparse calls:

    Little Endian Ubuntu:
    before took 382623 us
    after  took  36740 us
   
    Big Endian OpenBSD:
    before took 3138172 us
    after  took  180116 us

Re: UUID and perf

It is merged into util-linux https://github.com/karelzak/util-linux/ … db20e2b855