At Discourse we have been experimenting recently with getting our whole stack running natively on Apple’s new M1 machines. In the last few weeks things have come together and there are now a few of us using this setup for day-to-day development, with great results!
The vast majority of credit here goes to the Homebrew and Ruby teams - most stuff now ‘just works’ . The only changes we had to make at Discourse were to a few of our gems which had bundled binaries.
To summarise, in case anyone else would like to try it out:
Install Homebrew using their default configuration. If you already installed Homebrew under Rosetta, you’ll need to uninstall and reinstall the arm64 version
brew install redis,
brew install postgres
brew services start redis,
brew services start postgres
brew install email@example.com
(follow the provided instructions to add it to your
PATH, and restart the shell)
ruby --versionshould now show the architecture as
git clone https://github.com/discourse/discourse
mini_racerline in Discourse’s
Gemfileto point to this experimental branch
gem 'mini_racer', github: 'rubyjs/mini_racer', branch: 'refs/pull/186/head'
bin/rake db:create db:migrate
I’m sure that general idea will apply to most Rails apps.
In terms of performance, developing on M1 machines feels a lot faster than previous Intel MacBooks. We have some benchmarks which we use to compare development performance for Discourse. In most of the single-core CPU-bound tests, the M1 sits right up amongst latest-gen-cpu Linux desktops.
For multi-core workloads it’s respectable, although not quite matching those high-end desktops. Unfortunately for filesystem-based tasks we still seem to be plagued by the issues described in this topic, but the other performance gains do help to mitigate that.
As for ‘tips and tricks’, here are a few things that have been helpful to me:
If you’re ever unsure whether things are running natively, or under Rosetta, you can check the ‘Architecture’ column in Activity Monitor:
If you test/deploy your Rails applications in Docker, then they have a tech preview for M1 which has worked great for me. The only gotcha is that it will default to arm64 architecture, which might not be what you want, especially if you’re building an image to be deployed in production.
This default can be changed using the
--platformflag on a docker command, or via an environment variable
I’d be interested to know how many other people are developing Rails apps on M1. Have you seen performance gains? Any tips / tricks / gotchas to add?