What format of image loads the fastest in Emacs?

Recently, I commissioned an artist (NeoStricker on DeviantArt) to create a lovely custom icon artwork for me, which I proudly display on my dashboard:

During this experience, I learned that the size of this image greatly influenced how fast Emacs loaded, for obvious reasons. But that made me wonder, does the format matter? Webp is claimed to be faster for websites, but what image format is fastest on Emacs?

2 Likes

But that made me wonder, does the format matter?

It does, the library emacs uses for a specific format (e.g. rsvg for .svg and so on) matters as well.

Webp is claimed to be faster for websites, but what image format is fastest on Emacs?

You could benchmark different image formats in emacs in regards to their loading times:

(mapcar
 (lambda (my-image)
   (let ((start-time (float-time (current-time))))
     (with-temp-buffer
       (insert-image (create-image my-image))
       (redisplay))
     (message "Time to load %s: %f seconds" my-image
              (- (float-time (current-time)) start-time))))
 '("/path/to/some/cool.jpg"
   "/path/to/another/cool.png"
   "/path/to/a/pretty/amazing.svg"))

replace the list of placeholder paths with the actual image paths you want to benchmark. You should see the different loading times in your Messages buffer:

Time to load /home/wilko/devel/tmp/benchmark-img/emacs-logo.jpg: 0.001378 seconds
Time to load /home/wilko/devel/tmp/benchmark-img/emacs.png: 0.000744 seconds

and then choose according to that.

Your test shows png getting loaded faster, am I interpreting the numbers right?

Your test shows png getting loaded faster, am I interpreting the numbers right?

My test shows that the particular .png I choose loads faster than the particular .jpg I compared it to. This doesn’t always have to be the case (iirc .png decompression should be slower than jpeg decompression for a technically similar image, but then again I’m no expert when it comes to the technical details on how image decompression works).

The elisp snippet is meant as a benchmark that can be used to asses the loading times of different versions of the icon artwork, so it’s easier to choose which one to use on a dashboard that gets loaded when one starts Emacs. One could use it to bench technically similar images as well, but that’s not what I did in my example (probably should have! the test images are just visually the same, meaning they depict the emacs logo/the same thing, but technically they’re of different size and scale).