Portage uses copy_file_range
and friends when merging packages to the live filesystem when it can by providing wrappers of some Python stdlib functions.
If XFS (or another "good" backing fs is used), it can take advantage of it for you.
We've found a bunch of bugs over the years through this, in various filesystems, actually!
Take a look at https://wiki.gentoo.org/wiki/User:Sam/Memorable_bugs_I_like_to_reference for a list.
Unfortunately, Python itself doesn't automagically do this yet:
- https://github.com/python/cpython/issues/81338
- https://github.com/python/cpython/issues/81340
But you can see how we handle it at https://github.com/gentoo/portage/blob/22e027aef2ddb49d1c4e2423b5b1f3c209ac8efe/src/portage_util_file_copy_reflink_linux.c if interested.