Skip to content

Instantly share code, notes, and snippets.

@kouwei32
Last active April 14, 2024 16:42
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kouwei32/c101be682fc2e433e153ea131798caec to your computer and use it in GitHub Desktop.
Save kouwei32/c101be682fc2e433e153ea131798caec to your computer and use it in GitHub Desktop.
Fixes for Low-Latency Desktop Streaming stuttering on macOS (applies to Moonlight, Parsec, Stadia, Geforce Now, etc.)

macOS Yosemite and above utilize AWDL (Apple Wireless Direct Link) to handle data transfers to other AWDL-enabled devices (Macs, Macbooks, iPhones, etc.) over the Wifi Radio, without the need for a common underlying Access Point.

However, whenever AWDL is active (Bonjour discovery and any Airdrop, Airplay, and GameKit links and transfers), it will lock the Wifi radio for small intervals. For Bonjour discovery specifically, this comes to an effective packet spooling time of about 50-100ms, once per second (active transfers will be higher).

Obviously, this will create unacceptable latency spikes for low-latency desktop streaming apps. To disable the AWDL interface, use the following command in Applications > Utilities > Terminal (this requires you to be logged in as an Administrator and enter your password):

sudo ifconfig awdl0 down


sudo - run as root
     ifconfig - configure network interface parameters
              awdl0 - the virtual interface device used for AWDL
                    down - disable the interface

Note that this will prevent all users on the system from using Airplay, Airdrop, GameKit, etc. To reverse, use sudo ifconfig awdl0 up.

macOS may reenable the interface upon a restart. If you want to keep it off automatically, you can write an Automator application to execute that command, then put it into your Login Items (though it will ask for your password every time). To execute it as root automatically, you may have to write a launchd daemon property XML.

Additional reading:

https://stackoverflow.com/questions/19587701/what-is-awdl-apple-wireless-direct-link-and-how-does-it-work

https://arxiv.org/abs/1808.03156

man 8 ifconfig


To a lesser extent, the Location Service Wifi scan will also lock the Wifi radio, albeit no more than around once every 5 minutes. To disable it as well:

Settings > Security & Privacy > Privacy > Location Services > Uncheck

Note that this turns off geolocation completely, including for Find My Mac.

@kouwei32
Copy link
Author

kouwei32 commented Apr 26, 2022

Sample implementation for a single-liner which writes a launchd .plist that should execute the command on boot (requires Administrator to write):

echo $'<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n    <key>Label</key>\n    <string>script.awdl.autodisable</string>\n\n    <key>RunAtLoad</key>\n    <true/>\n    <key>LaunchOnlyOnce</key>\n    <true/>\n\n    <key>Program</key>\n    <string>/sbin/ifconfig</string>\n\n    <key>ProgramArguments</key>\n    <array>\n            <string>awdl0 down</string>\n    </array>\n</dict>\n</plist>' | sudo tee /Library/LaunchDaemons/script.awdl.autodisable.plist

To load this into launchd:

sudo launchctl load /Library/LaunchDaemons/script.awdl.autodisable.plist

@kouwei32
Copy link
Author

kouwei32 commented Dec 20, 2022

macOS Ventura has changed the behaviour of the AWDL virtual interface. Applications that request connections over AWDL will now automatically reenable the awdl0 device if it is disabled. The ifconfig command will still work, but if you have AirDrop etc. enabled locally, AWDL will be immediately reenabled. Bonjour discovery will also reenable AWDL once every few minutes.

It has been reported that disabling Bluetooth and setting AirDrop to "No One" can prevent proximity Bonjour discovery, but this may not be acceptable for users that use Bluetooth devices. No direct workarounds are known at the moment.

If you are using Monterey or lower, and heavily rely on low latency streaming for your tasks, it is highly recommended to not upgrade to Ventura yet. If you have already upgraded, as a last resort you can downgrade macOS by reinstalling from an older version in Recovery Mode.

See also AskDifferent: https://apple.stackexchange.com/questions/451646/

@kouwei32
Copy link
Author

kouwei32 commented Dec 22, 2022

AWDL has also been known to cause severe Wi-Fi degradation only on newer M1 Macs on Ventura 13.0 specifically, due to a driver implementation bug. If you experience frequent complete disconnections, update to 13.1+ (which patches the bug) or reinstall Monterey / another older macOS version.

@Kaylebor
Copy link

Kaylebor commented Feb 15, 2023

In combination with jc and jq, I created this function in Fish to fix this problem while using Parsec. This function toggles awdl0 status between active and inactive.
This is more manual than permanently disabling it of course, but I do want to keep these features active when I am not playing.

function parsec-fix
    if test (/sbin/ifconfig awdl0 | jc --ifconfig | jq -r '.[0].status') = active
        sudo /sbin/ifconfig awdl0 down
    else
        sudo /sbin/ifconfig awdl0 up
    end
end

I am using the raw path to ifconfig because my local brew is shadowing it with the GNU version.
jc is a command line tool (with packages in some languages like Python) that parses known popular CLI tool output to JSON, which makes it easy to read the status from the ifconfig output with jq

Of course, it should be trivial to transform this function into another shell or language; I do recommend installing jc and jq, as it is easier and more readable this way than using grep, but it shouldn't be too hard either if using PCRE2.

This variant should also toggle Location Services, but I am not 100% sure that it works, since the associated setting in Privacy Settings stays the same...

function parsec-fix
    set -f locationd_store /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd
    if test (/sbin/ifconfig awdl0 | jc --ifconfig | jq -r '.[0].status') = active
        sudo /sbin/ifconfig awdl0 down
        sudo defaults write $locationd_store LocationServicesEnabled -bool false
    else
        sudo /sbin/ifconfig awdl0 up
        sudo defaults write $locationd_store LocationServicesEnabled -bool true
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment