Why is Rails boot so slow on macOS?

I don’t know if I’m doing something wrong, or if it’s the corporate antivirus (Microsoft Defender) fault, but on my Macbook Pro with M1 Rails it takes several dozen seconds, even up to 50 seconds! to boot. This of course may be the fault of some corporate security software, but I am on Ruby compiled for arm64:

ruby 3.1.3p185 (revision 1a6b16756e) [arm64-darwin22]
ruby 3.0.5p211 (revision ba5cf0f7c5) [arm64-darwin22]

in both cases launching bin/rails c took ~ 40-50 seconds today

1 Like

Recommend you baseline it against something else, maybe try cloning Discourse on to your local machine and comparing. 40-50 seconds does not sound right to me and is not inline with what the various Discourse devs experience.

1 Like

in my case discourse starts rails/c in 30 seconds, fresh after reboot, it takes 5-10 sec for subsequent starts Apple M1 Pro 16GB RAM with Microsoft Defender and possibly some other software running in the background.

I recently switch from 2019 intel MBP to an M4 Pro and was shocked at the (lack of) performance. Started looking around and came across this thread and wondering if these results match up with what others are seeing? On the MacBook

Running benchmark on 1 core
--------------------

List View (json): 47.595 (±27.0%) op/s
Topic Create: 33.799 (±9.6%) op/s
Post Spec: 12.406 (±0.4%) seconds
PBKdf2 64000 sha256: 75.622 (±3.6%) op/s
Cook README.md: 275.209 (±19.7%) op/s
Discourse Boot: 1.673 (±1.7%) seconds
Random Read: 42.583 (±71.5%) op/s

Running benchmark on 14 cores
--------------------

List View (json): 334.326 (±74.3%) op/s
PBKdf2 64000 sha256: 771.567 (±19.1%) op/s
Cook README.md: 2229.99 (±42.4%) op/s
Discourse Boot: 0.523 (±1.3%) seconds
Random Read: 3404.206 (±95.3%) op/s


System Info
--------------------
architecture: arm64
kernelversion: 24.3.0
memorysize: 48.00 GiB
operatingsystem: Darwin
physicalprocessorcount: 14
processor0: Apple M4 Pro
virtual: physical
cores: 14
ruby: 3.3.1
pg_ctl (PostgreSQL) 17.4 (Postgres.app)
Redis server v=7.2.7 sha=00000000:0 malloc=libc bits=64 build=7f24f11dd7e42c58
ruby: no shim

./bench  677.90s user 596.17s system 446% cpu 4:45.15 total

On an Ubuntu vm on the MacBook

Running benchmark on 1 core
--------------------

List View (json): 84.387 (±20.5%) op/s
WARNING: V8 isolate was interrupted by Ruby, it can not be disposed and memory will not be reclaimed till the Ruby process exits.
Topic Create: 20.435 (±23.5%) op/s
Post Spec: 9.832 (±1.7%) seconds
PBKdf2 64000 sha256: 109.35 (±1.9%) op/s
Cook README.md: 319.527 (±17.3%) op/s
Discourse Boot: 0.845 (±1.6%) seconds
Random Read: 23678.584 (±70.1%) op/s

Running benchmark on 14 cores
--------------------

List View (json): 387.653 (±67.2%) op/s
PBKdf2 64000 sha256: 1104.391 (±20.9%) op/s
Cook README.md: 2116.882 (±44.8%) op/s
Discourse Boot: 0.1 (±3.0%) seconds
Random Read: 212496.243 (±270.0%) op/s


System Info
--------------------
architecture: aarch64
kernelversion: 6.13.7
memorysize: 15.66 GiB
operatingsystem: Ubuntu
physicalprocessorcount: 1
virtual: physical
cores: 14
ruby: 3.3.1
pg_ctl (PostgreSQL) 16.8 (Ubuntu 16.8-0ubuntu0.24.04.1)
Redis server v=7.0.15 sha=00000000:0 malloc=jemalloc-5.3.0 bits=64 build=3ec7bf4ec5bfafb8
ruby: no shim

./bench  894.11s user 139.08s system 555% cpu 3:06.15 total