Just to give an example for this:
Provided I launch discord using Plasma menus and its .desktop file is installed in ~/.local/share/applications
In ~/.config/systemd/user/app-discord@.service.d/override.conf
I put:
[Service]
CPUWeight=1000 # 1000 / 10000, 10%
CPUQuota=85%
MemoryAccounting=yes
MemoryHigh=1G
$ systemctl --user show 'app-discord@*.service' | grep ^MemoryHigh=
MemoryHigh=1073741824
Discord won’t ever use more than 85% CPU and gets a 20% priority in the application cgroup slice.
And discord won’t use ever use more than 1 GB of memory.
I did the same for my spotify launcher, but it has a space in the name so this needs to be escaped.
Using systemd-cgls | grep spotify I could find the systemd service name, mine was app-spotify\x2dlauncher@6a080f761acd4508b410fbce72dc7412.service.
So I copied the directory ~/.config/systemd/user/app-discord@.service.d to ~/.config/systemd/user/app-spotify\x2dlauncher@.service.d and now spotify has the same limitation.
This was mostly in Limit Application Memory Usage with systemd - KDE Blogs already, it was missing the “@” to add at the end before “.servide.d” and now you can just copy-paste.