Since MacOS 10.5 there is an API to copy files and directories recursively. These APIs are capable of copying the metadata along with the file contents.
(man copyfile, also new APIs here: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/APFS_Guide/ToolsandAPIs/ToolsandAPIs.html#//apple_ref/doc/uid/TP40016999-CH7-DontLinkElementID_11)
Additionally, these APIs are accelerated when running on top of Apple File System.