Simple Optimizations for macOS and iOS Build Agents
Reliable, repeatable CI/CD is a primary goal of all DevOps teams, but decreasing the time it takes for these processes to complete is generally the driver for additional iterations on a pipeline. Increasing the size and power of your hardware is certainly a direct way to achieve that, but there are also simple optimizations that you can make to your existing infrastructure to improve performance without increasing your CI/CD cost.
This post will call out simple, high-value optimizations for Xcode build agents that fall into one of two classes – freeing up an agent’s available processing power, and ensuring that an agent is up and available when called upon to execute a given job. Each optimization will be executable from the command line, so as to make it simple to layer these commands into your existing automation.
Free up CPU in a macOS build agent
Spotlight is a system-wide desktop search feature built into macOS. While it is a handy tool for desktop use, it works by creating an index of all items and files on the system, which eats up processing power that could be better spent on executing jobs in a CI/CD pipeline. Disabling Spotlight will free up CPU by reducing the disk I/O required to execute this indexing.
launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist || true
Note: If you get error 150, operation not permitted while System Integrity Protection is engaged, follow these steps to disable SIP. You can re-enable it after Spotlight is disabled.
Disable Siri / corespeechd
First released in 2010, Siri aims to help with a variety of tasks ranging from drafting messages, searching the web, playing music, and more. Again, this is handy for a single user who is logged into the machine directly, but it is a costly drain on CPU in the case of a macOS or iOS build agent. Disabling Siri, and the interwoven corespeechd process, will almost certainly free up CPU and make for more efficient builds.
plutil -replace Disabled -bool true /System/Library/LaunchAgents/com.apple.Siri.agent.plist
defaults write com.apple.Siri StatusMenuVisible -bool false
defaults write com.apple.Siri UserHasDeclinedEnable -bool true
defaults write com.apple.assistant.support "Assistant Enabled" 0
Ensure the macOS build agent is up when you need it
Disable System Updates
Because cloud-based macOS build agents are generally spun up in a virtualized environment, or cloned if they are running on bare metal, it is cleaner and more efficient to install your target OS just once, on a single machine. Disabling system updates will help to ensure that the build agent is up when a job is passed to it, rather than installing updates that you may or may not want.
softwareupdate --schedule off
This power-saving feature may reduce costs if you are hosting machines on-prem, but it is sure to increase build times, as the machine will have to wake up before it can execute a job. However, because MacStadium offers flat-rate pricing on all of our cloud-based, macOS solutions, simply disabling sleep will reduce build times at no additional cost.
systemsetup -setsleep Never
systemsetup -setharddisksleep Never
systemsetup -setcomputersleep Never
systemsetup -setdisplaysleep Never
Disable Screen Saver and Login Window After Timeout
When there is no screen to save, it just makes good sense to disable the screensaver, as it will eliminate the wait time that comes with the machine preparing for work again. Moreover, disabling the login screen after timeout will likely save more than a few headaches.
defaults write com.apple.screensaver loginWindowIdleTime 0
defaults write com.apple.screensaver idleTime 0
While you may need to increase your compute resources to get the performance your organization needs out of your iOS or macOS CI/CD pipeline, that shouldn’t be your first step. Instead, try these simple, free optimizations first. And if they don’t get your build times to your target, don’t hesitate to reach out to a MacStadium sales engineer to learn more about possible next steps.
Thank you to Shopify for sharing these optimizations with us, so we can share them with the larger MacStadium community!