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

Laptop:  Fedora 38 + rpmfusion + remi (SCL only)
x86_64 builder: Fedora 39 + rpmfusion + remi-test
aarch64 builder: RHEL 9 with EPEL
Hosting Server: CentOS 8 Stream with EPEL, rpmfusion, remi

Re: UUID and perf

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

Laptop:  Fedora 38 + rpmfusion + remi (SCL only)
x86_64 builder: Fedora 39 + rpmfusion + remi-test
aarch64 builder: RHEL 9 with EPEL
Hosting Server: CentOS 8 Stream with EPEL, rpmfusion, remi

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...

Laptop:  Fedora 38 + rpmfusion + remi (SCL only)
x86_64 builder: Fedora 39 + rpmfusion + remi-test
aarch64 builder: RHEL 9 with EPEL
Hosting Server: CentOS 8 Stream with EPEL, rpmfusion, remi

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

Re: UUID and perf

Ôrel wrote:

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

This one looks fine, I will try to do smth similar when I get to my property in Berlin today.