[Development] QML pixmap caching
martin.jones at nokia.com
martin.jones at nokia.com
Tue Jul 24 01:58:16 CEST 2012
> -----Original Message-----
> From: development-bounces+martin.jones=nokia.com at qt-project.org
> [mailto:development-bounces+martin.jones=nokia.com at qt-project.org]
> On Behalf Of ext David Faure
> Sent: Tuesday, July 24, 2012 12:42 AM
> To: development at qt-project.org
> Subject: [Development] QML pixmap caching
>
> QDeclarativePixmapStore (called QQuickPixmapStore in Qt5, but it's the
> same
> code) seems to throw away cached pixmaps, every 30 seconds, even if the
> cache is far from full.
>
> This creates a performance issue when an image are being loaded during
> animations, and was supposed to be in cache already.
>
> Here's my analysis of qdeclarativepixmapcache.cpp:
>
> The timer (called 30s after a pixmap becomes unused)g calls
> shrinkCache(_unreferencedCost / CACHE_REMOVAL_FRACTION); i.e. it
> wants to remove 1/4 of the unused pixmap data.
>
> And the shrinkCache method, if called with a positive number, will always
> remove at least one element from the cache:
>
> while ((remove > 0 || [...]) && m_lastUnreferencedPixmap) {
> // remove last unreferenced pixmap
> }
>
>
> So if you have a 10MB cache and an Image element that alternatives
> between two states by changing its "source" property, each image being
> 1MB, then it would all nicely fit into the cache, but shrinkCache will be
> called with an argument of remove=250KB and will delete the currently-
> unused image from the cache.
>
> Of course it's a matter of tradeoffs -- do you want to use more RAM to save
> on
> IO+CPU, or to minimize RAM usage, at the expense of IO+CPU the next time
> IO+the
> image is necessary....
> It's just that in the use case I'm seeing here, loading images from the SD card
> is too costly, so keeping them in RAM would be preferred.
>
> So maybe this should be configurable?
Perhaps. I'm wary of exposing details of the current implementation in API.
> Or is the only option to create my own QDeclarativeImageProvider which
> keeps everything in memory?
This is the only option at the moment.
> I'll do that for now, but it seems like there should be an easier way to tell
> QML "keep stuff in cache as long as the cache isn't too big" (and the cache
> size could possibly be made configurable, too, like in QPixmapCache).
I agree that the current strategy is too aggressively discarding images. The simplest solution I can think of is to have a lower and upper bound, so that the cache allows up to say 25% of its capacity to remain indefinitely. It should be possible to set the cache size too. This is a task that has been around for some time https://bugreports.qt-project.org/browse/QTBUG-19507
Br,
Martin.
More information about the Development
mailing list