When the host uses Sophos Antivirus, you may have a bad performance while compiling in the container.
This is described in the Sophos Support Site, which suggests to use "Fanotify" for on access scanning, which is unable to scan inside docker containers and thus solves the performance issues.
To set the descibed Fanotify option, you can use these commands described here:
sudo /opt/sophos-av/bin/savconfig set disableTalpa true
sudo /opt/sophos-av/bin/savconfig set disableFanotify false
sudo /opt/sophos-av/bin/savconfig set preferFanotify true
Alternatively you can consider to disable the AV daemons temporarily:
sudo systemctl stop sav-protect
sudo systemctl stop sav-rms
Afterwards you can restart again:
sudo systemctl start sav-protect
sudo systemctl start sav-rms