In some environments such as Java, it's natural to use TCP/IP sockets to pass messages between processes on the same host using the 'localhost' address (127.0.0.1 in IPv4, or ::1 in IPv6). (Because Java tends not to expose other IPC mechanisms in its API).
Clearly, this has the potential to be a lot slower than IPC via message passing over pipes, or IPC using shared-memory.
On the other hand, if the TCP/IP networking stack realised that both ends of the connection were on the loopback interface, it might be able to do a fair bit of optimisation so that the efficiency might not differ much from using pipes.
But do common operating systems (Windows, Linux) implement such optimisations in their TCP/IP stacks?