Opened 13 years ago

Closed 13 years ago

Last modified 5 years ago

#9284 closed patch

TOON: Cache recently used resources, rather than preloading

Reported by: eriktorbjorn Owned by: sylvaintv
Priority: normal Component: Engine: Toon
Version: Keywords:
Cc: Game: Toonstruck


Some time ago, I mentioned to SylvainTV that the Toonstruck engine uses a lot of memory for preloading entire PAK files, DREW.PAK probably being the worst offender since it's 20 MB that remains in memory for the duration of the game. This patch is an attempt at keeping the memory usage down by caching resources as they are used. I haven't tested it much, but it seems to work for me.

It's built on the assumption that Resources::getFileData() is for short-lived data (typically read from file and immediately copied to another data structure), so it doesn't matter if the actual data is removed from the cache, while Resources::openFile() is for long-lived data which the engine itself is responsible for handling so it doesn't go through the cache at all.

I'm sure there's room for improvements, but at least this demonstrates that the concept could work.

Ticket imported from: #3194044. Ticket imported from: patches/1389.

Attachments (1)

toon-resourcecache.diff (10.1 KB ) - added by eriktorbjorn 13 years ago.
Patch against current Git trunk

Download all attachments as: .zip

Change History (7)

by eriktorbjorn, 13 years ago

Attachment: toon-resourcecache.diff added

Patch against current Git trunk

comment:1 by fingolfin, 13 years ago

Owner: set to sylvaintv

comment:2 by fingolfin, 13 years ago

Sylvain, any comments on this?

comment:3 by eriktorbjorn, 13 years ago

Apparently it was accepted with a few modifications. At the very least, there was a bug in getFromCache() and the cache size was increased from 2 MB to 4 MB. (I picked 2 MB mainly because it allowed me to quickly get to the point where it would have to throw away cached resources.)

I knew SylvainTV had been looking at it (which is how I knew about the bug I had made), but I didn't notice it had been committed until now.

See commit 6873e9673213516539acca37c08b1d6c0bfaa350.

comment:4 by eriktorbjorn, 13 years ago

Status: newclosed

comment:5 by digitall, 6 years ago

Component: Engine: Toon

comment:6 by Thunderforge, 5 years ago

Game: Toonstruck
Note: See TracTickets for help on using tickets.