The changes made involve caching the decoded frames instead of decoding them repetitively. This considerably reduces the CPU usage when using looping media files, a common practice in the themes and overlays we see in live streaming today.
From our internal measurements, we see a CPU usage reduction of more than 35%, but this comes at a small cost: memory. The goal of this article is to explain this trade-off and what measures we have taken in Streamlabs Desktop to manage this.
Media file caching: what is it?
When your streaming software has a regular media file as your source (mp4, gif, mp3, etc.), it will open the file and then decode and display the frames at a specific speed (framerate for the video and sample rate for the audio).
Today, this process consumes a large number of CPU cycles. To remediate that, we added a new caching system. This means that when a media source is looping during your entire stream, we will read the decoded frames from the memory instead of using the CPU/GPU to decode the same data over and over.
What is the trade-off? Is this too good to be true?
As mentioned before, there is a trade-off to keeping decoded frames in memory. Decoded video frames can be large so they can’t be cached without restriction, otherwise, it would consume the entire available memory in your computer. In order to never allow this, we set a limit in the amount of memory Streamlabs Desktop will utilize for caching. This limit is 2GB. This means that if the decoded frames are larger than 2GB, they will not be cached in memory.
Additionally, we added a system that will monitor your local memory usage and manage it. This means that Streamlabs Desktop will react in real time to any spike in the local memory usage. In other words, if your game or other applications start using a lot of memory suddenly, this system will reduce the memory used by Streamlabs Desktop in order to keep your system running smoothly.
From our measurements, with the help of many live streamers willing to test this innovation, we’ve seen that this memory management works for a huge majority of cases and improves the streaming experience considerably. If streamers don’t want to use this CPU reduction, we’ve added an option to toggle off media file caching inside the advanced settings menu.
You can download Streamlabs Desktop here. If you have any questions or comments, please let us know. Remember to follow us on Twitter, Facebook, Instagram, and YouTube.