Especially during unmerge/replacement of a different version, emerge appears to progress very slowly. By using an NFS-based path to store the log files, I can see that the log file is opened, written to and closed again for each line it wants to write. I suspect this is done for other phases as well, only less obviously. Even on fast hosts, unmerging a package with many files (say, a kernel) and storing the log on NFS takes exceptionally long. I recently cleaned up old gentoo-sources installs and it took $reasonably_fast_host a couple of days(!) to unmerge some forty packages. So that's what got me here.
It's the _display_merge method that opens the log each time that it's called: https://gitweb.gentoo.org/proj/portage.git/tree/lib/portage/dbapi/vartree.py?h=portage-2.3.99#n2404
We can open the file once at the beginning of the _unmerge_pkgfiles method, and pass it into all of the _display_merge calls.