lunedì 25 maggio 2015

[Mac OS X] The ultimate Mac OS X performance optimization (updated when needed)

In my 20 years experience with Mac OS X (starting from 7.3 to Yosemite 10.10) I frequently need to debug or at least to tune up the System. Here is my tips & tricks archive for the everyday survival. This archive is updated as soon as I have new tricks: I need to store them somewhere to share between my Macs and to build an history for disaster recovery purpose.

For debug I mostly use Activity Monitor to inspect the problems (you find it in Application / Utility), looking at the CPU Tab, where I added the memory column (right click on the columns and just mark it) to have all in one place.

For problem solving, if you see the courier font it means that you must copy / paste that command in the utility / terminal.

Enjoy.


discoveryd uses 100% CPU after 10.10.3 upgrade
http://masugadesign.com/blog/easy-temp-fix-discoveryd-100-cpu-osx-10-10-3

temporary solution, but it works since a couple of weeks right now and my macs fans don't fly away like airplanes anymore. You could perhaps save it as a bash script and run it with a weekly crontab.

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.discoveryd.plist sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.discoveryd.plist

since the culprit could also be the bonjour service, it's better to flush all the DNS caches around your mac (I recently thrashed an airport express so it could have left traces on my Macs)
http://furbo.org/2015/05/05/discoveryd-clusterfuck/
http://osxdaily.com/2014/11/20/flush-dns-cache-mac-os-x/

sudo discoveryutil mdnsflushcache;sudo discoveryutil udnsflushcaches;

mds and mds_stores (Spotlight) eating 50% and more CPU
http://9to5mac.com/2014/02/11/how-to-get-spotlight-processes-back-under-control-when-cpu-usage-goes-crazy/

Open Spotlight Preferences. As soon as I dropped my user/Library/Application Support folder it falled to 5%. You can also disable indexing daemon when you perform intensive works (then turn it back on!)

sudo mdutil -a -i off

But this will cause Spotlight to stop working. An application like the freeware AppPolice could help in other cases (a simple slider will let you choose the max percentage of CPU a process can use), but although it shows Spotlight, mds and mds_stores aren't shown and limiting Spotlight doesn't affect them in any way: they will keep on consuming 99% CPU. You can work around it with cputhrottle utility (it must be installed) or nice / renice (prebuilt in any unix system but not hard-limiting). Since Process Renicer by eosgarden is discontinued and Process Wizard by La Chose is stuck on Leopard, I gave a try to Appriority (free edition not available on the App Store, download it from the website) but no way to select mds_stores. I think the only way is to renice known useless processes with a bash script at login: given a loop containing all the PIDs to renice (e.g. mds, AirPlay and other stuff)

sudo cputhrottle PID_to_limit max_percentage_integer

I will post the bash script as soon as I will do one. Meanwhile read these articles:
http://nixsos.com/limit-application-cpu-usage-in-mac/
https://github.com/maumi/cputhrottle

preview panel RAM eater
I was wondering how my RAM was eated on my Mac Book Pro 2011 and Mac Mini late 2011 and I inspected it with the free app Memory Clean. I experienced problems like apps that refused to open, a whole system like XP pre-service pack 3 and the famed windowsupdate fix, no way to work with finder, too strange to be on a Mac.

No way to get rid of this problem... I also read that Yosemite doesn't leave free RAM since uses it for the file cache: too strange because this is an energy consuming strategy and it's really far from everything I experienced in the Apple world since 1996.

Ok, I admit that I had the standard 4GB on both the computers and perhaps it wasn't enough for Yosemite. I upgraded them respectively on 12GB and 16GB and... my RAM was eaten!!!

It was time for a deeper inspection and, after several days, I noticed that it happened if I selected a word document (the preview panel, which is default on OSX, tried to show the preview content) and double clicked on it to open. Obviously the finder stuff stood in place, so under my document window while I was editing it, the finder keep the file selected and the preview panel trying to make the preview from it. Some kinda bug looped the RAM to death on both my Macs, blame on you Apple!

http://osxdaily.com/2013/01/10/disable-finder-icon-thumbnails-previews-mac-os-x/

The temporary fix is to open the view options wherever you like, disable icon preview, disable preview column, make it as default view and have a fast performing computer despite the fact that it's a temporary solution. Do you still need to preview anything while you're working on the finder? No problem, select it and press space!

misc utilitie
Select - copy - paste text directly from the Finder's Quick Look:

defaults write com.apple.finder QLEnableTextSelection -bool TRUE; killall Finder

I have an external audio card and I always get an annoying message on my audio app every time my HDMA screen wakes up after sleep: "Logic Pro is scanning your system for audio devices, and has detected a device named “DisplayPort”. You need to unload default audio drivers

sudo kextunload /System/Library/Extensions/AppleHDA.kext