-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Describe the bug
When sending a lot of images/frames with the graphics protocol, kitty becomes noticeably slower for each additional image load operation.
I've tracked this down to the disk_cache.c find_hole function, in particular the HASH_SORT of all the disk cache entries, which happens on each cache write operation.
Because this expensive operation happens inside a lock, it causes noticeable freezes when sending multiple images when the cache contains a lot of entries.
I encountered this issue when implementing an emote picker for Xithrius/twitch-tui#524. It requires me to load a lot of twitch emotes, which are mostly animated images, with some containing hundreds of frames. With some twitch channels having a few thousand emotes, the cache can become quite large.
Testing and loading all those images for one twitch channel resulted in a cache containing ~40k entries.
Note that those images are all small in size, and I am not close to hitting the storage quota.
I am loading those images lazily, but kitty starts to struggle after reaching a cache with a few thousand entries, which can in some cases be only ~50 emotes (each having 20-40 frames).
For this use case of sending a lot of images, without doing any deletion, the find_hole function call is not really necessary, and just commenting it out speeds up things greatly. There also seems to be a defrag operation happening when the cache gets too fragmented.
My question is, would it be possible to look into optimizing the disk cache when it contains a lot of entries? Or would it be best for me to start keeping track of which image has not been used recently, and tell kitty to delete it, to keep the number of cache entries low.
It would also probably be good to consider adding a maximum number of images quota, in addition to the maximum storage quota, to avoid DOS attacks.
To Reproduce
Steps to reproduce the behavior:
- Send a lot of images to kitty using the graphics protocol
- Once the disk cache starts to have a few thousand entries, kitty becomes really slow