Obscure techniques for developers to minimise macOS CPU, disk I/O and power consumption

updated Sat 11 Feb 2017

Me writing this blog post

Assuming you’ve done all the obvious things, e.g.: remove unwanted apps, close apps that don’t need to be open, remove System Preference pane based apps you can do without, tidy the Login Items list, free up sufficient disk space, upgrade RAM, remove unnecessary browser extensions etc.

  • Exclude every website, Git repository and virtual machine on your Mac from Spotlight search.  This made an incredible difference in CPU activity for me (the mdworker and mds processes are what to look for in Activity Monitor).
  • Reduce the quantity of files in your Dropbox folder. It can’t cope with hundreds of thousands of files, or at least the indexing process on initial login can become lengthy and CPU intensive as you near Dropbox’s own estimate of 300,000 files.  Avoid having any Git repositories in there – just make sure you (a) have local backups (Time Machine only backs up certain files and directories) (b) you’re pushing to GitHub, Bitbucket or somewhere else off-site regularly.   Download AWS CLI and sync a .tar.gz occasionally with an S3 bucket.
  • If you use PhpStorm, turn off all the Language Injections you don’t need, turn off all the Inspections you don’t need and remove any unnecessary plugins.  You’ll almost certainly have a handful of candidates for each of those three areas – i.e. languages or frameworks you never use.  Just familiarise yourself with what’s available every now and again so if you do work on an unusual project you have a better chance of remembering to turn the necessary options back on.

(P.S. I’m still using El Capitan 10.11.6 and have no plans to upgrade for several months.)

Mac load average

$ sysctl -n vm.loadavg
{ 1.29 1.38 1.45 }

If you think the Mac load average seems high compared to Linux, here’s an explanation of how it’s calculated.  The CPU idle % is a more useful measure of how loaded your system is (the above measurement was taken with 97% idle CPU).

Troubleshooting Drupal\Core\Template\Loader\ThemeRegistryLoader – Unable to find template

(NB: this post refers to Drupal 8)

You may see an error like this if you’re developing a theme with caching disabled and twig.config.auto_reload on, and you’ve just removed a template from a subtheme:

Twig_Error_Loader: Template “themes/custom/test/templates/field–node–title.html.twig” is not defined (Drupal\Core\Template\Loader\ThemeRegistryLoader: Unable to find template “themes/custom/test/templates/field–node–title.html.twig” in the Drupal theme registry.)

To get rid of this you need to clear the theme-registry , until you do that it won’t correctly fall back to the equivalent file in your base theme.

Similarly, if you add if you add an extra template to a subtheme, Drupal will ignore it and continue to use the base theme until the theme-registry is cleared. (You won’t get an error, but you’ll wonder why your changes haven’t been reflected.)

To reset it:

drush cc theme-registry

or:

drush cr

The latter is less precise and takes longer to run, but is quicker to type the first time. Or you can use drush cc and pick the number the menu.

Note this happens (for me) regardless of whether twig.config.cache is true/false or whether the dynamic page cache is disabled.

Getting voice memos off an iPhone

If you are having problems losing the will to live transferring voice memos saved on your iPhone using iTunes in iOS10, I would suggest you give up following tutorials and fiddling with the sync settings and just get a program called iMazing – you plug the phone in, go to Voice Memos, shade the ones you want, click Export, and choose a directory you want to save them in. (They remain on the phone.)

(There’s a free trial and you can either buy it directly – £35, or it’s in the new SetApp monthly maOS app subscription, which is $10/month but is also in a free-beta period until the end of January 2017.)

Blocking spam text messages on iOS 10

I’m blogging this because the user interface in different parts of iOS isn’t consistent so it’s not immediately obvious how to do it.

Supposing you receive a spam/unwanted text from a particular number (a full number or shortcode, doesn’t matter.)

– open Messages and view the conversation
– Click the (i) symbol in top right corner
– Click phone number on following screen (not the icons, to the left of the screen where the actual number is, you may not think it’s clickable but it is)
– The next screen will have a Block this caller link at the bottom

This is confusing because there are other ways to bring up a similar screen but without the Block option at the bottom.

Tested in iOS 10.1 and 10.2

backup2l troubleshooting – skipcond not ignoring paths

Something to watch out for…

backup2l, the popular Unix backup software, has a setting in /etc/backup2l.conf called skipcond that lets you ignore files/paths.  It uses find syntax.

You might have written something like this if you don’t want to both backing up old logs, say:

SKIPCOND=(-path /var/www/mysite/system/cms/logs/log*" -o -name "*.o")

But when you run backup2l -e to simulate the backup, it says:

856 / 43210 file(s), 13 / 5003 dir(s), 2.2GB / 4.3GB (uncompressed)
skipping: 0 file(s), 0 dir(s), 0 B (uncompressed)

You know this is wrong for two reasons, the overall size is too big and it’s not skipping anything.

This could be because of symlinks.  To debug, run a real backup (with the -b switch), and use backup2l -l [pattern] (where pattern is some file(s) you know are in the directory you want to exclude) to see what’s there.

You may find it’s actually backing up /usr/share/nginx/mysite, because /var/www is symlinked to it:

lrwxrwxrwx  1 root root    17 Aug  2  2015 www -> /usr/share/nginx/

Remember backup2l has a purge (-p) option that lets you remove individual differential or incremental backups by specifying the number. So if you’ve just run all.1375, say, you can delete that with -p 1375 and when you run it again it’ll reuse the number.

 

Keys

First they came for the § key, and I did not speak out –
Because I could never remember what it was for.

Then they came for #, and I did not speak out –
Because you just press opt+3* (and who uses it other than developers?)

Then they came for Delete, and I did not speak out –
Because you could still use Fn + backspace and in any case I had a full size, wired numeric keyboard.

Then they came for F13-F19, and I did not speak out –
Because they were so far away.

Then they came for the full height arrow keys, and I did not speak out –
Because I had mapped up and down to J/K with the Vimium extension.

Then they came for Pg Up/Down, Home & End, and I did not speak out –
Because my full size keyboard still had them and the icons confused me.

Then they came for Escape, and I did not speak out –
Because I could map it to Caps Lock (where it should have been all along) and I wasn’t planning to buy a Macbook anytime soon anyway.

* British layout

Why developers should turn off smart quotes

Ocassionally I write commands in my notes app before copying and pasting them into iTerm.  It’s very easy to type “regular quotes” and not notice macOS has converted them into “smart quotes”.

Then your command doesn’t run, and you get an error message that doesn’t make any sense because the arguments aren’t being parsed correctly, but you don’t notice at first it’s the quotes that are wrong because the font is too small and your mind is fixated on looking for spelling mistakes and syntax problems…

To turn them off, on a Mac go to:

System Preferences > Keyboard > Text > uncheck “Use smart quotes and dashes”

iOS 10 tips

Updated Fri 7 Oct 2016 with note about Emergency Bypass

  • Avoiding having to manually click/press the home button to unlock the phone when you are viewing the notifications screen (there isn’t any benefit to this on iPhone 6 or 6s).  Go to: Settings > Accessibility > Home Button > turn on “Rest finger to open”.The caption on the lock screen will still read says “Press home to open”, but you only need rest your finger on the TouchID sensor. Note this option is only available if the device has TouchID – if you don’t have a fingerprint sensor, you must click the (mechanical) button manually.
  • (not new to iOS 10) – if you are fed up of accidentally bringing up the Apply Pay / wallet screen because you clicked the home button twice by mistake when the display was off, go to Settings > Apple Pay and Wallet and turn “Double-Click Home Button” off – with this, double clicks will just wake/unlock the phone instead.
  • There’s a new Emergency Bypass setting in contacts.  You can set it separately for ringtones and texts and it’s described as allowing “sounds and vibrations from this person even when Do Not Disturb is on.”Be aware, however, it means your iPhone will sound for that person regardless of the position of the Ring/Silent switch – this may mean you don’t want to use it after all, if you want to guarantee your device will be silent when the switch is set to silent.

    I opened a bug report about it with Apple who closed the radar and marked it as “behaves as intended.”

Film: What Comes Next is the Future

Due for public release next year (I’ve watched the full version and there are quite a few screenings left) this is a great film about the history of the World Wide Web, covering early browsers, table-based layout, the pros and cons of Flash, browser compatibility, the birth of web standards and css, responsive design, the web versus apps…