I’m building a program with C and GTK 4 which uses 6 large-ish images in the UI (about 300x300 px).
The images are stored in a
GResource generated by something along the lines of the following:
<?xml version="1.0" encoding="UTF-8"?> <gresources> <gresource prefix="/images"> <file compressed="true" alias="image1.svg">images/image1.svg</file> <file compressed="true" alias="image2.svg">images/image2.svg</file> <file compressed="true" alias="image3.svg">images/image3.svg</file> <file compressed="true" alias="image4.svg">images/image4.svg</file> <file compressed="true" alias="image5.svg">images/image5.svg</file> <file compressed="true" alias="image6.svg">images/image6.svg</file> </gresource> </gresources>
And then used when a window is created using a
GtkBuilder with a UI file containing something along the lines of this:
... <object class="GtkPicture"> <property name="file">resource://images/image1.svg</property> </object> ...
for each image. This works just as I’d like it to in almost every way - it seems to be a very clean solution.
The problem is, it is slow to load each window - it takes about ~1s for the window to appear.
I have noticed that if I change this to use a 128x128px PNG it dramatically improves loading times - but I’d rather use SVGs, for the improvements in file size and resolution, especially on larger screens where an adequately high-res PNG would be quite large.
What ways could I go about improving the loading time of my windows? (I understand I may have to load the picture in C rather than in the UI file.)
So far my thoughts are:
- lazily loading the SVGs, which seems like it could be nice, since the images are in a separate tab of a
GtkNotebookfrom what is displayed at startup (just delaying the lag until the user switches tab isn’t really a solution, but loading them in the background could be)
- using some kind of background idle process, although if it still blocks for the duration of loading one image for each image, this might not really improve matters much, since it seems like each individual image is already pretty slow.
However, I’d be very interested to hear any ways I could improve my application’s responsiveness regarding these slow SVGs.
Many thanks in advance.