• .NET Developer Tools DevTools

    UI controls for ASP.NET AJAX, MVC, WPF,
    Silverlight, Windows 8 and Windows Phone

  • Hybrid Mobile Development Icenium

    Cross-platform Mobile Development Tool
    with cloud-based architecture

  • HTML5 / JavaScript Development Kendo UI

    Everything you need to build sites and
    mobile apps with JavaScript and HTML5

  • Testing Tools TestStudio

    One easy tool for Functional, Performance,
    Load and Mobile software testing

  • Web Presence Platform Sitefinity CMS

    Everything for your online business - content
    management, ecommerce, emarketing

  • Agile Project Management TeamPulse

    Simple and intuitive project management
    and collaboration software

Contact us

We are here for you.
  • usa+1‒888‒365‒2779
  • uk+44‒20‒7291‒0580
  • bg+359‒2‒8099850
  • de+49‒89‒2441642‒70
  • au+61‒2‒8090‒1465
  • emailsales@telerik.com
Your account Access to your products, updates and support
Telerik Product Families
  • Your Account
    Your Account
    Log in
  • ABOUT US

    About Telerik

    • Company
    • Press Center
    • Customers
    • Community
    • Careers
    • Contacts
Kendo UI - The way of HTML5
Products ▼
Kendo UI Web Kendo UI Mobile Kendo UI DataViz Server Side Wrappers
Demos Purchase Download
Blogs Documentation
Support ▼
Premium Forums StackOverflow Forums
Resources ▼

Featured Resource

Kendo UI Dojo


Blogs Code Library Demos Documentation FAQ Testing
Premium Forums Roadmap User Voice Videos Webinars More Resources
Contact Us Search
 

Blogs

JavaScript Performance On Mobile Devices

Friday, October 07, 2011 by Kendo UI Team Blog | Comments 4

While working up a blog post today on creating a simple game with HTML5 , I tested the app on my iPhone and found something quite interesting.  It was ridiculously slow.

You can check out the application here and see it’s performance on your mobile device.  It appears to have trouble with drawing to the canvas on iOS.  The premise of the game was to have multiple images floating up on the screen at the same time.  Lots of drawing to the canvas taking place.  In an attempt to reduce the drawing, I used two canvas laid on top of each.  One for the background and one for the beach balls.  This meant I only had to draw the background once and could leave the other canvas for the repeated draw at the browser frame rate.

<canvas id="background" width="640" height="480"
 style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
<canvas id="balls" width="640" height="480"
 style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>

This did not help at all.

It’s Not A Canvas Problem.  It’s a JavaScript Problem.

As it turns out, iOS JavaScript performance is pretty shoddy when compared with modern desktop browsers.  Below is a performance test I did according to the SunSpider speed test from WebKit .  The measurement is the total number of milliseconds that it took the test to run in each browser.

Screen Shot 2011-10-05 at 5.45.21 PM

What’s shocking aside from the fact that IE 9 was the fastest browser, is how bad the performance is on iOS WebKit.  It’s 18 times slower than the slowest desktop browser. 

Now I know this is an “Apples To Oranges” comparison.

The desktop browsers are running on a MacBook Pro with a 2.2 Ghz i7 processor an 8 gigs of ram.  My iPhone has the Apple A 4 chip which clocks in at 1 Ghz on the iPad but is probably under-clocked on the iPhone to preserve battery life. I wouldn’t expect the performance to be nearly as good as a desktop.  IE On Mango fairs much worse than iOS at a whopping 35 times slower than Firefox on a Dell Venue Pro with a 1 Ghz chip. 

However

Given those test results, it’s clear that we cannot write HTML5 apps for the mobile platform without taking this into account.  If HTML5 apps and games are the way of the future on mobile devices, how do we make this work?

CSS 3 Transitions

CSS 3 is the new CSS specification for HTML5.  Transitions allow you to animate elements of the DOM with pure CSS.  No JavaScript required.  You basically specify what property you want to animate, how long the animation should take to run, and an easing function.  Then whenever the CSS property changes (ala jQuery), the change is animated.

The built-in easing functions are Linear, Ease, Easein, EaseOut, EaseInOut.  If these don’t suit you, you can specify your own via a custom easing function. The Ceaser CSS Easing Animation Tool will create your custom easing for you.

The are also some sites like http://css3generator.com/ which will generate your CSS 3 for you.

The reason why CSS 3 transitions are so powerful, is that they are optimized for the GPU on the device.  The browser doesn’t have to parse arbitrary JavaScript to try and figure out what you are trying to do.  The browser essentially doesn’t know that you are trying to achieve a smooth animation when you are doing it via JavaScript.  When you use CSS transitions, the GPU magic happens under the covers and your animations are smooth.

That being said, my implementation used requestAnimationFrame which is recommended by Paul Irish and I still noticed poor performance on iOS.  The canvas is additionally optimized to use accelerated graphics when it can, but clearly that is not sufficient when drawing so many objects to the screen.

Browser Support

Like many things, CSS 3 is not yet fully supported or standardized across all browsers, so we have a different prefix for each of the current major players.  Whenever there is a feature that the browser makers want to implement, but no concrete w3c standard to back it up, they all implement it with some prefix that is specific to their browser so that when the standard is adopted their conventions won’t collide with whatever is decided on by the standards body.

That means in order to properly target your transitions at all browsers, you would need something like this.

-webkit-transition: all 500ms linear;
-moz-transition: all 500ms linear;
-ms-transition: all 500ms linear;
-o-transition: all 500ms linear;
transition: all 500ms linear;

That’s a bit messy, but you can always use things like LESS or SASS to clean it up.

As Todd mentioned, it’s always something with IE .  Currently, IE does not support CSS 3 transitions.  Not even in version 9.  That means you better have a fallback plan if you are going to rely on CSS 3 transitions as last month’s browser usage statistics still show IE with 22.9% of the market.  That’s way too big of a chunk to completely ignore.

Screen Shot 2011-10-05 at 5.38.04 PM

Source: http://www.w3schools.com/browsers/browsers_stats.asp

Notice though that there is a –ms-transition.  That’s there for the emerging IE 10 browser which does support CSS 3 transitions.  IE is catching up slowly but surely.

Kendo UI And CSS 3

CSS 3 performance on iOS is top notch.  It’s clear that you have to consider all platforms when choosing the best  animation in your application, either through CSS or JavaScript.  Kendo UI makes use of CSS 3 for transitions whenever possible and degrades to jQuery / JavaScript transitions for weaker browsers (* cough *  IE  * cough *).

These are the unseen things to consider when picking an HTML5 framework.  Will your framework provide a solid experience on mobile devices?  Will your UI translate from the desktop to the tablet?  It’s important that we leave no browser left behind as we create new applications on a standard that is still in a bit of flux.  Kendo UI allows you to concentrate on building your UI and less on having to worry about whether or not it’s going to work when the next tablet ships (i.e. Kindle Fire ).

About the Author
Burke Holland is a web developer living in Nashville, TN. He enjoys working with and meeting developers who are building mobile apps with jQuery / HTML5 and loves to hack on social API's. Burke works for Telerik as a Developer Evangelist focusing on Kendo UI. Burke is @burkeholland on Twitter.

4 Comments

  1. 1 Daniel 03 Nov 2011
    We have reached november! What day can be expected to see the mobile KendoUI goodies?
  2. 2 Stefan Rahnev 03 Nov 2011
    The official Kendo UI v1 release is slated in the very end of November. With it we will provide the first preview of the Kendo UI Mobile bundle.
  3. 3 xxo 12 Dec 2011
    It ok
  4. 4 john mcfetridge 03 Apr 2012
    the javascript performance is not a surprise and I think it leads to the following conclusion:

    Hybrid phone frameworks(HTML5/JS) are a great idea for many apps like a contact manager where most of the UI is rendered by CSS. The minute you look at compute intensive app like a game then you must go native. Hopefully over time this will change but I would not count on it being soon.

Comment

  1. Click to add

  2. Click to add

  3. Click to add

  4.    
     
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
     
      
       
Blogs feed
Categories

  • Tutorials (26)
  • Release (33)
  • Browsers (7)
  • Extensions (3)
  • Tip of the Week (10)
  • Videos (5)
  • Concepts and Theory (13)
  • Misc. (25)
  • Framework Constructs (6)
  • Mobile (6)
  • UI Widgets (5)
  • Blogs (1)
Archive
  • 2013 May (8)
  • 2013 April (10)
  • 2013 March (9)
  • 2013 February (12)
  • 2013 January (10)
  • 2012 December (9)
  • 2012 November (11)
  • 2012 October (6)
  • 2012 September (7)
  • 2012 August (8)
  • 2012 July (10)
  • 2012 June (8)
  • 2012 May (10)
  • 2012 April (7)
  • 2012 March (13)
  • 2012 February (10)
  • 2012 January (6)
  • 2011 December (10)
  • 2011 November (4)
  • 2011 October (6)
  • 2011 September (5)
  • 2011 August (9)
Home Web Mobile DataViz Server Wrappers Whitepapers Surveys Chrome Icenium Contact Us

Kendo UI framework is developed by Telerik - a leading provider of UI components for web, desktop and mobile applications. Trusted by over 100,000 customers worldwide for our devotion to quality and industry-best technical support, Telerik helps professionals maximize their productivity and "deliver more than expected" every day.

kendoui - powered by html5, css3 & jquery
get social
  • Twitter
  • Facebook
  • Google plus
  • RSS
Privacy Policy | Branding Guidelines
Powered by Sitefinity CMS

Copyright © 2011 - 2013 Telerik Inc. All rights reserved.