How to reduce Spotify's memory (and not only) consumption

Posted on June 13, 2021

Intro

I love listening to music. I even love when it comes to nice services. Why wouldn’t I spend some pennies on something which just works well?
So I use Spotify. Spotify is good, except when it comes to its consumption. It consumes too much of your computer power, memory and even your data.
If we try to get the memory consumed by Spotify using ps_mem, we see that Spotify’s app uses ~ 400 MB to play the song/podcast/etc.:

Private   +   Shared  =  RAM used	Program

405.8 MiB + 656.1 MiB =   1.0 GiB	spotify (6)

And the question is why?

Spotify app uses underneath the very problem of current desktop apps - Electron. If you’re going to list the spawned child processes via ps -aux | grep spotify, you will notice the chromium instance. And Electron is a thing that is kinda built on top of Chromium. Currently, lots of apps use Electron in order to do their job, since developer hours are expensive, you can have one codebase written on JavaScript, while the hardware became cheaper. Discord, WhatsApp, Twitch, Slack, VSCode, etc. are built using Electron. It’s not a big deal if you have only one of these apps. But it’s a problem if you have a bunch of them. Hence when it comes to such situation you can imagine having a plethora of browser tabs on any browser which uses the same engine behind as Chrome does - yes, it’s a total nightmare.

Is there anything which can be done on that?

Apparently, there is an option (otherwise I wouldn’t bother myself writing that article, xd). I discovered spotify-tui, the command-line client, which has to be bundled with spotifyd, lightweight libre Spotify daemon. They both are written purely in Rust and they consume around ~25 MB:

Private  +   Shared  =  RAM used	Program

11.3 MiB +  12.7 MiB =  24.0 MiB	spotifyd
12.8 MiB +  13.7 MiB =  26.4 MiB	spt

And here’s how it looks:

(Rigellute/spotify-tui, github.com)

It has enough features, that you probably use 90% of the time. I haven’t tried it using full desktop environments, but I guess that playerctl can introduce you to all the needed buttons like play/pause/stop/etc. for your app bar.

And what even better is that spotifyd is libre, so you don’t mess with /etc/hosts/ and adding there all these noisy add trackers (less consumption of bandwidth by default).

PS: consider having Spotify Premium, otherwise it won’t work.