Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it still worth using eval for performance on mobile JavaScript?

To combine all modules into a single resource, we wrote each module into a separate script tag and hid the code inside a comment block (/* */). When the resource first loads, none of the code is parsed since it is commented out. To load a module, find the DOM element for the corresponding script tag, strip out the comment block, and eval() the code....

On an iPhone 2.2 device, 200k of JavaScript held within a block comment adds 240ms during page load, whereas 200k of JavaScript that is parsed during page load added 2600 ms. That's more than a 10x reduction in startup latency by eliminating 200k of unneeded JavaScript during page load!

http://googlecode.blogspot.co.uk/2009/09/gmail-for-mobile-html5-series-reducing.html https://developers.google.com/speed/docs/best-practices/mobile

The gmail article is more than three years old and there's been great advantages in mobile performance since then, namely things like iOS's Nitro and JIT coming to mobile. Are the performance gains still to be had from using eval?

like image 371
Robert Daly Avatar asked Oct 29 '13 12:10

Robert Daly


1 Answers

Its not the same technology issue as it was before since JavaScript engines have become so performant. Rather there are other considerations in terms of being more app-like.

enter image description here

There are tricks now that are different in approach such as using web workers for ajax requests to free up the thread, utilizing the GPU with CSS transformations and requestAnimationFrame or even asm.js. Using localStorage/sessionStorage and Application Cache is another approach along those lines where you can really get a lot of client-side caching up front to avoid calling anything more than the content JSON / images data urls / videos and load/execute things into memory as needed from those caches.

Its a different time in other words and your question is interesting but not focused in the right areas to really make a difference in web-app performance.

like image 197
King Friday Avatar answered Sep 20 '22 18:09

King Friday