For wlroots-based compositors like sway here's the most lightweight solution: https://hg.sr.ht/~scoopta/wlrobs
For mutter (GNOME): https://github.com/flatpak/xdg-desktop-portal + pipewire
My favorite way to record on wlroots compositors is wf-recorder, which seems to be lighter on resources than the others.
There's also a fork of SimpleScreenRecorder (with similar issues, unfortunately).
Here's an overview of screencasting tools for wlroots based compositors like Sway and Wayfire: https://github.com/solarkraft/awesome-wlroots#screencasting
For wlroots-based compositors like sway here's the most lightweight solution: https://hg.sr.ht/~scoopta/wlrobs
For mutter (GNOME): https://github.com/flatpak/xdg-desktop-portal + pipewire