phoboslab / qoi

The “Quite OK Image Format” for fast, lossless image compression
MIT License
6.83k stars 328 forks source link

decode preformance improvement #256

Closed ProkopRandacek closed 1 year ago

ProkopRandacek commented 1 year ago

Hi :D I split up the main decode loop into two loops - one for the run op filling and one for the rest.

./qoibench 10 ~/Downloads/images/ --noencode --onlytotals --nopng Original:

# Grand total for /home/prokop/Downloads/images/
        decode ms   encode ms   decode mpps   encode mpps   size kb    rate
qoi:          2.1         0.0        225.74          0.00         0    0.0%

+ separate run loop

# Grand total for /home/prokop/Downloads/images/
        decode ms   encode ms   decode mpps   encode mpps   size kb    rate
qoi:          1.9         0.0        242.92          0.00         0    0.0%

+ restrict pointers

# Grand total for /home/prokop/Downloads/images/
        decode ms   encode ms   decode mpps   encode mpps   size kb    rate
qoi:          1.9         0.0        241.86          0.00         0    0.0%

The restrict pointers didn't gain any noticible speedup but I have noticed on compiler explorer that the compiler couldn't eliminate some loads because void* could alias with the other pointers, which the restricts solved.

phoboslab commented 1 year ago

Sorry for the delay. While the decode performance improvement is quite substantial (at least for those images with many runs) I'm not a fan of having the pixel assignment in two different places now. Faster implementations already exist and I think this particular implementation's goal should be readability.

restrict is sadly a C99 thing and qoi.h aims to support c89.