Slashdot Mirror


An Interesting Look At the Performance of JavaScript On Mobile Devices

First time accepted submitter faffod writes "Coming from a background of console development, where memory management is a daily concern, I found it interesting that there was any doubt that memory management on a constrained system, like a mobile device, would be a concern. Drew Crawford took the time to document his thoughts, and though there is room for some bikesheding, overall it is spot on. Plus it taught me what bikeshedding means."

31 of 157 comments (clear)

  1. Mobile web really IS slow! by EvanED · · Score: 5, Funny

    Don't blame Timothy for the dupe; no doubt he posted it from his mobile.

    1. Re:Mobile web really IS slow! by faffod · · Score: 2

      Sigh... I did look back to see if it had been posted, didn't go far enough. *hangs head in shame*

    2. Re:Mobile web really IS slow! by Trepidity · · Score: 4, Insightful

      Since this was literally the same link, not just the same story but via a different source, it seems like there could be a pretty simple automated dupe-checker that flags it and tells the editors: a story with the same link was posted in the past N weeks, are you sure you want to post?

    3. Re:Mobile web really IS slow! by Mitchell314 · · Score: 2

      I'm surprised I haven't seen anybody publish a script that sees if something similar has been posted in the recent past on slashdot based on key words or some analytics voodoo. Would make for an interesting project, and fitting too!

      --
      I read TFA and all I got was this lousy cookie
    4. Re:Mobile web really IS slow! by phantomfive · · Score: 5, Funny

      Quick! Now's your chance! Go copy a high-rated comment from the other story and get yourself a +5 moderation!

      --
      "First they came for the slanderers and i said nothing."
    5. Re:Mobile web really IS slow! by phantomfive · · Score: 4, Funny

      For a real salute to recursion, I personally copied that comment from a previous dupe......

      --
      "First they came for the slanderers and i said nothing."
  2. Chek your speling by Rob_Bryerton · · Score: 4, Funny
    From TFS:

    ...and though there is room for some bikesheding, overall it is spot on. Plus it taught me what bikeshedding means."

    But it didn't teach you how to spell it...

    1. Re:Chek your speling by Anonymous Coward · · Score: 3, Funny

      <Ralphie Wiggam> The missing 'D' was used for my grade. </Ralphie Wiggam>

    2. Re:Chek your speling by slashmydots · · Score: 2

      Spelling isn't important in programming, lol. That's what the IDE is for. Coincidentally, most IDEs for javascript have little to no spelling assistance, lol.

    3. Re:Chek your speling by arth1 · · Score: 2

      I'm glad I don't work with you, if you laugh at loud for every sentence you write.

    4. Re:Chek your speling by GigaplexNZ · · Score: 2

      Spelling isn't important in programming, lol. That's what the IDE is for. Coincidentally, most IDEs for javascript have little to no spelling assistance, lol.

      Tell that to Microsoft who had to break compatibility due to some spelling mistakes. Specifically, the MFC/ATL section.

    5. Re:Chek your speling by lxs · · Score: 2

      I like the comma before "lol." Write sentence, little pause, bellylaugh. Classic.

    6. Re:Chek your speling by MrBandersnatch · · Score: 2

      "Spelling isn't important when writing. Thats what the word processor is for!"....."lol"

      You're me at 13 aren't you? :)

  3. Typical console developer rant, IMO. by goruka · · Score: 3, Interesting

    I'm probably going to get downvoted as troll, but my experiences with most console developers were often strange (as a developer myself).
    Talks usually end up in most of them dismissing scripting languages, higher level APIs (such as OpenGL), or certain algorithms as useless because they are slow, use too many instructions unnecessarily, waste cache, etc.

    Any attempt to raising a point about how you don't need to optimize everything but only few critical zones of your code (what matters), or that a cache wasting algorithm can end up being faster anyway just because it's more efficient, immediately results in myself being dismissed or treated as ignorant because, something inefficient is obviously inefficient and I must be stupid for not realizing that.

    This article reminds me of that. The author claims (in his first claim) that he is determined to prove that something is less useful because it's slower, and nowhere in that huge long piece of text there is anything useful offered as proof, instead he keeps posting data about how slow Javascript really is.

    1. Re:Typical console developer rant, IMO. by Anonymous+Brave+Guy · · Score: 2

      Any attempt to raising a point about how you don't need to optimize everything but only few critical zones of your code (what matters) ... immediately results in myself being dismissed or treated as ignorant

      To be fair, if you were debating with someone who writes applications that really do need the very top levels of performance, and you claimed that optimising trouble-spots would be sufficient to achieve that, then you were ignorant. For most software, being within a factor of 2 or 3 of hand-optimised low-level code is easily sufficient, and a bit of work with the profiler to identify the most serious flaws will go a long way. The rules change when you shift from that kind of performance standard to needing the very top levels, because then the emphasis on speed permeates everything.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    2. Re:Typical console developer rant, IMO. by Arker · · Score: 2

      They arent useless but they are certainly not always the best (or even simply an appropriate) tool to use. Scripting is great for the trivial-but-useful, particularly a one-off or a mock-up. But any sort of serious computer program is going to be better if you program it and most anything that is trivial-but-useful enough to have a jscript app should be quickly reproducable on any platform that you want in a native fashion. Do you need a native program to have a simple calculator? No, javascript will do. And that's great.

      At the same time, if that simple calculator is something you use very often, make an app. You dont have to be worried about the simple calculator overwhelming your phone to think that makes sense - because we all multitask these days and/or worry about electricity/battery life etc. on many devices.

      It's funny seeing how people are rediscovering the importance of programming as a result of these phones. The reason it makes me chuckle is that I remember working with PCs that had orders of magnitude less system resources than these phones do, so I understand that it is actually the abstraction layers in use that make the hardware seem so limited.

      You kids nowadays think a power-throttled ARM processor and a couple gigabytes of RAM is 'limited resources.' You should try a z80 with 8kb ram. Believe it or not, if you actually program the thing instead of expecting your libraries and abstraction layers to deal with it for you, you could make that work too.

      --
      =-=-=-=-=-=-=-=-=-=-=-=-=-=-
      Friends don't let friends enable ecmascript.
    3. Re:Typical console developer rant, IMO. by arth1 · · Score: 5, Insightful

      The problem is that your baby is not the only thing running on the system. When you waste resources, you do it on behalf of everything else that runs too. Even if your baby isn't doing anything critical when you waste it.

      It only takes one selfish programmer to screw up an embedded system. You are he.

    4. Re:Typical console developer rant, IMO. by UnknownSoldier · · Score: 2

      > Talks usually end up in most of them dismissing scripting languages, higher level APIs (such as OpenGL),

      A few years back I've implemented OpenGL on the Wii and did maintenance work on our OpenGL version running on the PS2. Hell, even shipped a couple of games with it. OpenGL 1.x _can_ be implemented efficiently on a console if you apply some discipline. People who dismiss a rendering pipeline probably have never implemented one. HOWEVER, their point is that memory manage CAN be an issue if one isn't careful. ( NOTE please don't confuse the misapplication with the theory: Broadcom has a garbage implementation of OpenGL ES 1.x & 2.x across there devices from the ones I've worked with, but there is no reason it needs to be that bad. Apple has a very nice OpenGL ES implementation.)

      > I'm probably going to get downvoted as troll, but my experiences with most console developers were often strange (as a developer myself).
      > Any attempt to raising a point about how you don't need to optimize everything but only few critical zones of your code (what matters),

      No, the reason you should get down modded is BECAUSE your mindset is part of the problem not the solution,

      1. You don't understand the first rule of computing:

      TINSTAAFL: There Is No Such Thing As A Free Lunch.

      I do not know to the extent you are but lazy developers are spoiled by their excessive Virtual Memory, slow high level languages, and including every bloated 3rd party library under the sun and the kitchen sink that OVERALL add to a SLOW machine. Great developers _constantly_ keep optimizations a low priority THROUGHOUT the writing process in the background so they don't have go and clean up all the crap later. Your mentality of "we will fix it later" is the sign of an immature and inexperienced programmer.

      2. Your boss / peers are trying to teach you an important lesson:

      Do It Right The First Time!

      and

      Keep is Simple, silly!

      THAT is the point -- not your uneducated rant about "Who cares about memory usage, memory fragmentation, garbage collection, memory leaks, cpu cycles, etc." -- well your USER does EVEN if they don't understand the technical terms. ONCE you say the user experience is no longer important you have FAILED as a programmer. People are the SOLE reason software even exists in the first place. Please stop this shitty attitude that "performance doesn't matter -- we'll just throw more hardware at it." No! NO! NO! How about doing the best* with what you have instead?? ALL your code should be (relatively) clean, simple, fast, efficient. This has the side-effect that it is EASY to maintain to boot! Who wouldn't want. And you are going to make excuses that you can't be bothered???

      * Apply the 80/20 rule for time-management in case it wasn't obvious.

      To bring this back on topic, Javascript is a badly designed & implemented language because of

      a) lack of memory control which leads to memory fragmentation and bloat, and
      b) lack of types and which forces the run-time to do extra unnecessary work if they had designed the language properly in the first place.

      There is a time and place for everything. Just never forgot to keep asking the questions: Can we do this better?

      --
      "Necessity is the Mother of Invention, but Curiosity is the Father." -- Michaelangelo

  4. Crisis Averted! by GreyLurk · · Score: 4, Insightful

    Whew, I'm glad we managed to get everyone to switch off of memory-leaking and CPU intensive Flash stuff over to standards compliant HTML5 and JavaScript then!

  5. Bikeshedding = Slashdot by Flere+Imsaho · · Score: 2
    --
    It gripped her hand gently. 'Regret is for humans,' it said.
  6. Spell-check in IDEs by tepples · · Score: 4, Informative

    Coincidentally, most IDEs for javascript have little to no spelling assistance

    Spell-check in IDEs generally relies on static analysis of the variables in scope at any given point in the program. The more dynamic a language's type system is, the harder it is to statically find the names of symbols in scope at any given point in the program. PHP and Python are kinda-sorta OK for this because all global variables are out-of-scope (PHP) or read-only (Python) unless declared otherwise at the top of a function's definition (or, in PHP, unless the variable is one of the predefined superglobals, whose names are all uppercase starting with $_). This way, the IDE can parse a function for all variables assigned to in a function and assume they're local. JavaScript, on the other hand, defaults to making all variables global unless declared local with the var keyword.

    Spell-check also relies on static knowledge of what source code files are in scope. This is dead easy for Java. In PHP you scan for require_once, and in Python you scan for import, but even then, a module is occasionally conditionally imported, and importing has side effects. JavaScript can't include JavaScript at all except by appending a <script> element to the HTML DOM with the src= attribute referring to the other script, and the idiom for that is harder to recognize than a simple import statement.

  7. What's better than JS? by tepples · · Score: 2

    It looks like you want to get rid of all JavaScript in web pages. What's a better way to present interactive forms over the Internet that doesn't involve reloading an entire 100 kB page whenever the tiniest bit changes and doesn't involve paying someone to make six different native applications, one for each operating system?

    1. Re:What's better than JS? by Arker · · Score: 4, Interesting

      I am not the GP but I sympathise with his comment.

      "It looks like you want to get rid of all JavaScript in web pages. What's a better way to present interactive forms over the Internet that doesn't involve reloading an entire 100 kB page whenever the tiniest bit changes and doesn't involve paying someone to make six different native applications, one for each operating system?"

      Dont force a single 100kB monster to begin with, doh. Break the monster down into bytesized chunks and this suddenly doesnt look so impossible to do in straight html, now does it? You can even keep your 100kB script as well if you want, but you must put a link to the straight version in the noscript tags at the very least. (Personally I urge you to give me an option to use the straight version even in a scriptless browser, otherwise you will probably force me to disable all scripts on your site, but it's not a formal requirement like the noscript tag.)

      From day one that was the way you were supposed to do it when you added scripts to your web pages, and it's not that I want to remove all scripts from the web, I want to remove this idiotic assumption it's ok to skip the webpage, hand out a script instead, and pretend all is well. It isnt. Javascript is fine for making a fancier version of a webpage (but only as long as you dont use it as an excuse to skip the simple version.) But scriptless browsers are an integral part of the web as long as it's existed and they arent going away. If you dont support them you arent supporting the web and are missing the point of the web.

      With the current threats and trends in malware, you're likely to see only more and more scriptless browsers. Browsers that support scripts just fine are being told not to support YOUR scripts - at least not until you are trusted. Making a good first impression more and more means making a good first impression WITHOUT grabbing your ecmascript crutches, without just ASSUMING that the visitor is immediately comfortable enough with you to be touched in that way.

      Even if you cant figure out how to write a webpage or hire someone that knows, you should not need to pay for 6 different native apps - unless your app has a really niche market at least. Just get it written once in a high level language, release it GPL so that anyone interested in porting it to a new platform can. You'll likely have ports contributed back faster than you can pick out the right guy internally to receive them. (This part assumes your app does something that a computer literate person might find useful, of course, it strikes me that is a blind assumption though.)

      Dont tell me your afraid to release your precious source - you're doing that right now every time your server sends out 100kB of ecmascript already.

      --
      =-=-=-=-=-=-=-=-=-=-=-=-=-=-
      Friends don't let friends enable ecmascript.
    2. Re:What's better than JS? by foniksonik · · Score: 3, Informative

      Sorry. Things change. It won't be long before browsers are just wrappers around the JSVM and all web addresses are just sandboxed applications running in it. The web is the biggest App Store there is.

      You want raw data in a structured format? There are REST APIs for that, they return JSON. HTML is too verbose by far as the default response and is useless for any other client besides an HTML renderer.

      Text content is moving to Markdown as a standard as well. It's quicker and easier and covers text formatting. Clients should just render it directly.

      I could go on but it's probably lost on you. Suffice to say that modern server app development is evolving to be service driven and client agnostic. HTML is one of many targets. Why write server apps or content engines (CMS/blog/forum) for a single client when you can instead create a server based API and several thin client apps (JS, DART, iOS, Android, C++, .Net, Lua, etc).

      --
      A fool throws a stone into a well and a thousand sages can not remove it.
    3. Re:What's better than JS? by evilviper · · Score: 2

      It looks like you want to get rid of all JavaScript in web pages.

      He doesn't, but he makes a good point that "2%" performance isn't good enough, and you should avoid javascript if you can.

      I consider this most important for projects like Firefox OS, which are pushing a platform for slow, mobile devices, where Javascript is the only programming language available.

      What's a better way to present interactive forms over the Internet that doesn't involve reloading an entire 100 kB page whenever the tiniest bit changes

      In my extensive experience, reloading the page every time is actually still FASTER and makes for a more responsive experience. Compare gmail with JS or in classic mode... Classic mode isn't as shiny, but it sure moves a lot faster. Or look at Netflix's queue... Insane delays from clicking the "move to top" arrow, until it actually happens, or the delete button, while reloading the page on each button press would happen in a fraction the time, and would work far better on low-end devices (and they wouldn't need a super-crippled "mobile" version of their site).

      A tiny bit more load on your server, in exchange for a much more responsive client-side experience. A bit more bandwidth usage, but compression and caching of all other page elements should make it pretty insignificant.

      --
      Slashdot gets worse every day... Pipedot: News for nerds, without the corporate slant
  8. The editors don't RTFA by tepples · · Score: 4, Funny

    it seems like there could be a pretty simple automated dupe-checker that flags it and tells the editors

    It's called the "visited link color" function. Or perhaps not even the editors read the featured article.

    1. Re:The editors don't RTFA by Anonymous Coward · · Score: 2, Informative

      - Is there only one editor, who always reads every single featured article?
      - Are slashdot editors barred from clearing their browser histories?

    2. Re:The editors don't RTFA by tepples · · Score: 2

      Is there only one editor, who always reads every single featured article?

      Ideally, the buck is supposed to stop with an editor-in-chief.

  9. More Full Response by El+Royo · · Score: 4, Insightful

    I made a comment to a poster over on the original posting of this. I think it's worth expanding upon in case people are persuaded by the arguments in the paper.

    First off, just as TFA predicts, I'm not going to try to conquer his mountain of facts and experts by presenting a mountain of citations. Instead, I'm going to point out where his conclusions are not supported by his facts and point out his straw man arguments and his attempt to convince us through overwhelming expert opinion.

    The straw man: In the article, he presents two scenarios (photo editing and video streaming) and claims that you can't reasonably do those because of memory limitations (on the iPhone/iPad). He then concludes you can't produce useful apps because you can't do those two. I couldn't find any citations of people attempting to do this on mobile using JavaScript. Choose the right tool for the job here. I'll give him these two use cases (and several others: 3D Games, audio processing, etc), however to extrapolate from here that no useful apps can be produced (ever!) using JavaScript is a leap too far.

    Next, he spends a lot of time diving into the particulars of garbage collection (GC). I'm going to grant him practically every point he made about GCs. They're true. And, it's true that mobile is a constrained environment and you must pay attention to this. But, this is largely known by developers who are trying to write high-performance JavaScript applications on mobile. Hell, -anyone- writing high-performance apps in any language need to be aware of this. If you allocate memory during your animation routines in a game you're asking for trouble, regardless of the language. So, to me, this part is just a call to pay attention to your memory usage in your apps. This is really useful advice and I will be paying even more attention to the new memory tools available in the latest Google Chrome dev tools.

    One of the biggest problems in the rant is the comparison of pure computing performance and his claim that ARM will never be as fast as desktop. I'm going to again grant that this is true. However, this means crap-all for most apps. Tell me: How many apps do you have one your phone that are processor bound? None? One? Two? The vast majority of apps spend their time either waiting on the user or, possibly, waiting on the network. You can write a lot of really useful apps even given constrained processor and memory. Anyone remember the Palm Pre? The TouchPad? Most of those apps were JavaScript and they worked just fine.

    This brings me to the point of all this, TFA's author focuses on performance. However, users focus on responsiveness. JavaScript is perfectly capable of producing responsive applications. Sometimes, it takes attention to detail. Nothing is ever 100% free and easy. JavaScript is not a magic solution and those of us who think that JavaScript has a future in mobile app development know this. This is why programmers get the big bucks. Writing mobile apps, you need to be aware of the effects of CSS, memory, processor, responsiveness and more.

    --
    Author of Enyo: Up and Running from O'Reilly Media
  10. TLDR version by Rob_Bryerton · · Score: 4, Informative

    Actually a pretty well written piece, if a bit wordy. I see a lot of people commenting here are perhaps missing the point, thinking that the author's angle was JS=BAD. Not at all. My take was his issue was not so much with JavaScript, but with Garbage Collected languages in general.

    An important point he made regarding GC routines and how they tend to be unpredictable in terms of when and how long they run. Also, much was discussed on his observations that, if you have several times more memory available than what your app needs, the GC routines are very non-intrusive. However, when you get into a low memory situation, the performance hit from GC is huge and causes obvious stutters in the application and/or it's UI.

    Also, some discussion on the irony of working around (or trying to "spoof") the GC by using various manual techniques, and how that almost amounts to manual memory management. All in all, a really interesting read.

  11. node.js by dutchwhizzman · · Score: 5, Funny

    Try looking into node.js and see all your fears come true.

    --
    I was promised a flying car. Where is my flying car?