So recently I left the world of Desktop PCs (at home at least) and bought myself a luscious 15″ Retina Macbook Pro. The 2nd thing I installed was Mono (the 1st was Windows 7 natch!).
Why a Mac?
I’ve been using Windows since Windows 95 and had every home version of the OS since – including ME and Vista. And I’ve enjoyed them all. Windows 8 has changed that (although I technically own a licence to that too – what can I say – I’m a sucker). Theres no way I can stick with that OS for the next 4 years…….
Add into the mix my 1 year old son, whose fascination with my desktop PC and swinging from its DVD drives, and the space it takes which is far more useful as toy storage – a new laptop was in order.
Apple was immediately in the running. 2880×1800 was why. Nothing else. I’d buy that. My iPad 3 screen was stunning – imaging writing code on a screen that nice. I hesitated though. As a long time Windows user I spent a long time looking for a high spec Dell or HP or anything that could come close. Every time I managed to spec something close a weird thing happened – it was more expensive than the Macbook Pro Retina. At least on a Mac I could install Windows and have MacOS as a second OS.
I caved in last month (Christmas coming and that desk space was reserved for a brand new trike). I really wanted to give MacOS a shot tho, so I installed Mono and MonoDevelop straight away.
Mono on a Mac wasn’t my first shot at using Mono. I also bought myself a Raspberry Pi this year.
A 700Mhz ARM CPU and 256Mb RAM for £25 was simply too tempting. I had to have one. On release there were no OSes to support its hardware floating point unit so all software used software floating point emulation – on an already slow 700Mhz CPU it was painful. But (for fun) I ran a Raytracer I’d written in F# on it to see how it compared to my home Q6600 and my work’s i7. More on the result later.
Back to Mac
So that same Raytracer I ran on the Windows part of my Mac. A simple scene at 1280×720 – 2 spheres and a plane with 3 lights. No fancy features – just ray hits surface, ray reflects, recurse. It ran in < 1 second. 1.5 times faster than my work i7 and 2.5 times faster than my Q6600 it was replacing.
Booting in MacOS I re-ran the test in Mono. 5 minutes 30 seconds. Around 330 times slower than the same exe on the same hardware. Just the OS and the runtime differed.
My heart sank. I love F#. I love C# (less). I didn’t buy a Mac to do Objective-C. I just wanted decent hardware to write .NET flavoured code on. And I sort of wanted the OS to be MacOS. I’d just assumed that Mono would be fast enough on such sweet hardware.
Oh and by the way – that same exe running in software on a Raspberry Pi on Mono – 10 minutes. Only half the speed of the 2.6Ghz i7 with 16GB of RAM. My dream of ditching out of Windows and using Mono on Mac was starting to look a lot like it was a really poor choice. I started thinking I’d have been better off buying 2 Pi’s and saving the best part of 2 and a half grand.
So I tweeted this:
“F# Raytracer on Win7 MBPr – ~1sec Under Mono on MacOS – 5:30. Minutes. 330 times slower on exact same hardware. Boo!”
I hadn’t hash-tagged it or aimed it at anyone. It was my attempt to cry about a sufficiently large duff purchase to my 50 or so followers (for them to ignore). But someone read it and added Miguel De Icaza to a retweet. Suddenly I started getting tweets from Miguel asking for code snippets and samples.
At this point I kinda felt like I’d hurt his feelings – his tweets sounded that way. After a quick round of tweets he reveals that Mono 3 defaults to the old garbage collector and that if I used the new garbage collector I’d get speeds *much* closer to .NET. I already knew I had GC issues on .NET – the profiler in VS2012 told me I had a large number of collections – something I worked around on .NET by switching off concurrent GC. Mono’s older GC simply magnified the issue.
I’d simply typed at a terminal
and complained when it didn’t work the way I expected first time. I should have tried more options before venting.
For reference Miguel also tweeted this – clearly aimed at me:
Pro-Tip: If you are using Task Parallel Library or using lots of threads with Mono on OSX, make sure you use SGen, or suffer the pain.
At least I wasn’t going to regret the Mac now, even with egg on my face.
It’s not perfect, but it is great. Here’s why:
- It exists. Despite everyone saying when it started that MS would shut it down and sue anyone using it – it’s still here.
- They care. It’s their whole business. They monetize it with MonoTouch/Droid/Mac. The create the free stuff with it and for it. While it feels like MS are busy firing up the furnaces to throw .NET in, Miguel and his team are planning a daring rescue. And it looks more and more likely that it may work. Even more recent MS castoffs are getting new leases of life on Mono – think XNA/Monogame.
- They really care. Had I tweeted that .NET performance sucked would MS have asked for samples? Heck even if you send samples to MS you’re likely to be ignored. If you’re lucky on a public forum you might get a handy tip from a passionate team member, but largely you’re ignored by the masses – except, of course the wonderful F# team who have always been super reactive to my team at work. Miguel answering is almost like Steve Balmer replying to a tweet on a .NET issue.
So apologies to the Mono team for my initially (but also unintentionally) rude tweet. Thanks for the help and the continued work. I’ll continue to use and enjoy it and stop whinging about it.
Any news on making Mono work with HardFP on the Raspberry Pi🙂