Why is my hostname resolution taking so long?
I was able to fix this issue by explicitly setting the HostName using scutil to be the same value as LocalHostName:

$ scutil --set HostName $(scutil --get LocalHostName)


Now:

$ sudo scutil --set HostName MacBook-Pro
$ time python -c 'import socket; print(socket.getfqdn())'
MacBook-Pro
python -c 'import socket; print(socket.getfqdn())'  0.01s user 0.00s system 86% cpu 0.016 total


I was confused before because of the following:

$ scutil --get LocalHostName
MacBook-Pro

$ hostname
MacBook-Pro.local


But:

$ scutil --get HostName
HostName: not set