Skip to main content

PlayCanvas versus Unity WebGL

· 6 min read

A question we get asked a lot is "How does PlayCanvas compare to Unity's WebGL export?". So let's examine this in a blog post.

But first, let me quickly introduce Unity and PlayCanvas to the uninitiated. Unity is a game engine provided as a native, desktop application for Windows, Mac and Linux. PlayCanvas is an HTML5/WebGL game engine that is provided as a web application that runs in any browser on any operating system.

For the purpose of this article, we're keeping things simple. We've created the 'Hello World' of apps in both Unity 5.3.2 and PlayCanvas: a spinning, textured cube:

The application above is the PlayCanvas app. I'm not embedding the Unity app since it can crash the page (if you're feeling brave, click here to run it in a new tab).

We decided to look at 3 key metrics: download size, load time and frame rate.

Download Size

To check the download size of each app, we disabled the cache in Chrome Dev Tools and recorded the total transfer:

UnityPlayCanvas
4.72MB0.22MB

The Unity app is over 21 times larger than the PlayCanvas app. How is this possible? The PlayCanvas engine is a miniscule 147KB when GZIPped meaning the code and assets for the app account for the remaining 73KB. The engine is so small because it is hand-crafted in JavaScript, relying on as much functionality as possible from the browser itself.

Unity, on the other hand, relies on Emscripten to export to WebGL. This tool auto-converts C# code to C++, which in turn is compiled to LLVM before finally being turned into JavaScript. A side effect of this process is the generation of huge amounts of code, which bloats the exported application, overwhelms modern JavaScript engines and often causes the browser to run out of memory.

Load Time

We ran both apps on 12 different devices, from low end to high end. These were the recorded load times on a 50Mb/s connection to the net:

DeviceBrowserUnity (s)PlayCanvas (s)
iPhone 4SSafariCrash2
iPhone 5SSafari181
iPhone 6Safari171
iPad Mini 2Safari211
Samsung Galaxy Tab S2Chrome 51191
Samsung Galaxy Note 10.1 2014Chrome 51281
Samsung Galaxy S6 EdgeChrome 51281
Samsung Galaxy Note 4Chrome 51281
LG Nexus 4Chrome 51442
Leapfrog EpicChrome 51431
Blackberry Z10Default BrowserCrash1
PC (Core i7 + GeForce GTX 880M)Chrome 51131

Key things to notice:

  • The PlayCanvas app's load times are up to 43 times faster than the Unity app.
  • The Unity app fails to even load on lower end devices. The sheer amount of JavaScript causes the browser on those devices to run out of memory loading the page.
  • Load times for Unity are up to twice as slow in Chrome as Safari. This could be down to Chrome spending more time preparing the app's huge JavaScript codebase for execution.

Frame Rate

Here are the frame rates recorded for the same set of devices:

DeviceBrowserUnity (fps)PlayCanvas (fps)
iPhone 4SSafariCrash58
iPhone 5SSafari2160
iPhone 6Safari2860
iPad Mini 2Safari1660
Samsung Galaxy Tab S2Chrome 5117-5560
Samsung Galaxy Note 10.1 2014Chrome 5115-5060
Samsung Galaxy S6 EdgeChrome 5115-5060
Samsung Galaxy Note 4Chrome 5115-5760
LG Nexus 4Chrome 5115-5060
Leapfrog EpicChrome 5116-5560
Blackberry Z10Default BrowserCrash60
PC (Core i7 + GeForce GTX 880M)Chrome 5157-6060

Key things to notice:

  • PlayCanvas frame rates are up to 4 times greater than Unity. In particular, Unity seems to perform poorly in Safari on iOS.
  • Unity exhibits very unstable performance in Chrome for Android. Initially, the app's frame rate is in the mid to high teens for approximately 20 seconds before it starts to rise to a number in the 50s. At that point it, it regularly drops frames and never reaches a solid 60FPS.
  • PlayCanvas easily locks to 60FPS across all devices except iPhone 4S where an occasional frame is dropped. Ideally, a much heavier stress test would be required to start taxing PlayCanvas.

Conclusion

To summarize:

  • Unity WebGL apps are up to 21 times larger.
  • PlayCanvas apps load up to 43 times faster.
  • PlayCanvas app frame rates are up to 4 times higher.

Even for the most basic of 3D apps, Unity struggles to achieve anything close to acceptable download size, load time and frame rate. It's important not to somehow blame browser vendors or HTML5/WebGL for these results. As PlayCanvas proves, you can achieve incredible performance using these web technologies today as long as a sensible approach is taken when architecting an engine.

To learn how PlayCanvas built an engine so optimized for the browser, head over to GitHub to explore the open sourced runtime. And if you want to start building with PlayCanvas today, sign up on playcanvas.com.

Update

If you want to look at the original projects that built the two apps used in the article, here is the Unity project, and here is the PlayCanvas project. After publishing this article, we noticed that the Unity project disables hardware anti-aliasing and uses bilinear filtering on the textures, whereas PlayCanvas enables AA and trilinear on the textures. So PlayCanvas is actually doing more work here.