A heavy build can freeze the desktop, so I start it inside a limited cgroup.
systemd-run --user --scope -p MemoryMax=2G -p CPUQuota=200% make -j8
systemd-run puts the command in a transient scope unit with the given properties, and the limits disappear when the command exits. CPUQuota=200% allows two cores in total. --user uses your own systemd instance, so no root is needed. The limits only work when the system uses cgroup v2 and the matching controllers are delegated to your user manager. If a controller is missing, the limit has no effect, so test with a command that really uses the memory or CPU before you rely on it.
Further reading: systemd-run manual page