Poor threading performance on MacOS 10.13.6


I have a weird problem that may or may not be a Rust issue that I hope to get some insight on. Apologies if this has been asked before (I did do a search!).

I'm learning Rust by writing a ray tracer and so far it's been super fun, Rust is a great language.

I recently noticed that the performance of my ray tracer has taken quite a hit (Note: I'm using --release when compiling). While rendering with 8 threads, Activity Monitor's CPU history shows that 4/8 virtual cores are being used and CPU usage hovers around 380% . I could have sworn that previously when I specified 8 threads to render the image, all 8 virtual cores were used and I would get CPU usage in the 780-800% range. When compiling, rustc seems to be able to use more than this, with CPU going as high as ~600%.

I tried the following:

  • Made sure I was on the latest stable Rust, then cargo clean; cargo build --release
  • previous stable versions of Rust 1.20 to 1.27
  • Ran the same program on Windows 10 Bootcamp (Linux Subsystem) and noticed that all 8 virtual cores were being used and the CPU went to 100% (800% on MacOS). Test scene render time on Windows 10: 38.889422 seconds, MacOS: 78 seconds
  • Tried my ray tracer on my desktop at work, which runs linux and is a 6 (12 threads) core machine. When running, all 12 virtual cores were being used.

So, on Windows 10 running on the same laptop as MacOS and my work's variant of Linux, all virtual cores are being used, but on MacOS, only half.

My program's only dependencies are:

image = "0.10.4"
rand = "0.3.15"

Which I use to write a png image and generate a random numbers. I doubt either of these dependencies is causing an OS dependent threading issue (but they could?).

Does anyone know what the issue could be?

Thanks in advance!


Some specifics on my setup:

  • Macbook Pro 15" (2015)
  • CPU: Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz (4 cores, 8 threads)
  • MacOS 10.13.6
  • Rust 1.28.0 (9634041f0 2018-07-30)
1 Like