When you’re developing for iOS, there is pretty much no other game in town other than Xcode. And if you’ve needed to use it for any period of time, you know: it’s a memory hog. Not just Xcode, but the iOS simulator, Interface Builder, debugger… You can easily use several GB of memory with just the iOS development tools alone. If you have 8GB of RAM (or 4GB… 😱), it’s enough to bring Xcode to its knees, and your blood pressure to a boil. When your code completion starts lagging to the point you can’t type… 🤬
It’s 2019. Shouldn’t your machine be thinking faster than you?
But your problem may be more than just Xcode. You may want to look at what else is running on your machine to see if you need to put it on a RAM diet.
Today, we live in the world of enormous browsers and Electron apps. Browsers and browser-based apps are turning into full-fledged operating systems in their own right — and use enough memory to match. And because Electron apps each run their own instance of a web browser (Chrome) to present their app functionality, you could have multiple browser runtimes running on your machine at the same time, each taking 1-2GB of memory a piece. To run a web page. The desktop Slack app is the most cited example of this.
Run a few of these, and all of a sudden, it isn’t Xcode being the only memory hog. And that doesn’t include the several GB of RAM devoted to the operating system itself.
Once you’ve filled your memory, everything runs slow, because the operating system needs to decide what to keep in memory. And swap things in and out to your disk to keep the illusion that everything is in memory. Even with our souped-up SSDs, disks are slow.
Executive summary: Computers are great at multitasking, until they aren’t.
So if your Xcode is lagging, take a look at what you have open on your machine using Activity Monitor. Use the Memory tab and sort the Memory column to see your major abusers.
If you have other memory hogs, here are some things you can do:
- If you are using an app to access a web-based service, consider using your web browser. You probably can’t kill your web browser anyway, so you may as well share the overhead.
- If you have an app that you don’t need open for iOS development, temporarily shut it down to reclaim that memory.
- Browsers are a pretty opinionated decision, but if you do not have a strong preference, consider switching to a lighter choice. Or perhaps, use that lighterweight browser just during coding sessions.
Hopefully once Marzipan is fully available, we’ll live in a world of Mac-ified iOS apps that run using much less memory than their Electron counterparts. Until then, practice some memory hygiene to improve your Xcode performance.