Skip to content

Implementing TCP_NODELAY significantly improves network performance for several games

I was recently investigating the quality of goldberg, and noticed that for several games, the networking is a lot more jittery compared to steam. After some debugging, I pinned this down to nagle's algorithm - at least on windows

As a quick test, if you add the following two lines to the top of set_socket_nonblocking in network.cpp:

    int flags = 1;
    setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&flags, sizeof(flags));

This improves the quality of the networking significantly, and makes the steam versions of stormworks and PlateUp much more playable through goldberg. This is something that's also doable via the registry on windows as well, though the code solution is much better

The technical explanation is: TCP by default aggregates packets into bigger chunks to reduce bandwidth. For games this is a poor default choice, as you want low latency over pure bandwidth usage. There are some other options that would help here as well, but TCP_NODELAY is the main one

For future work: It may also be worth investigating how significantly TCP_QUICKACK and SIO_TCP_SET_ACK_FREQUENCY (on windows, for the latter), affect tcp performance for games, as both of these can significantly improve performance in latency bound situations