最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Why does Javascript run so slow on iPhone? - Stack Overflow

programmeradmin2浏览0评论

I've been researching writing an app for iPhone. I really like the look of PhoneGap which basically allows you to contain a webpage in an app. My skills are primarially in HTML/Javascript so this tool allows me to make the most of my skills without having to spend many hours learning how to write an app natively for the iPhone.

I've been doing some tests on my iPhone for Javascript, and some seemingly simple examples run painfully slow. Really slow. This unfortunatly is a big problem for my task!

Any work arounds? If I want to do anything interesting am I going to have to write a 'proper' app?

An explanation on why Apple have seemingly created such a bad implementation of Javascript would be interesting as well (possibly to make more money? Less web apps = more apps in the store?)

References

I've been researching writing an app for iPhone. I really like the look of PhoneGap which basically allows you to contain a webpage in an app. My skills are primarially in HTML/Javascript so this tool allows me to make the most of my skills without having to spend many hours learning how to write an app natively for the iPhone.

I've been doing some tests on my iPhone for Javascript, and some seemingly simple examples run painfully slow. Really slow. This unfortunatly is a big problem for my task!

Any work arounds? If I want to do anything interesting am I going to have to write a 'proper' app?

An explanation on why Apple have seemingly created such a bad implementation of Javascript would be interesting as well (possibly to make more money? Less web apps = more apps in the store?)

References

http://ajaxian.com/archives/ipad-javascript-shockingly-slow

Share Improve this question asked Jul 22, 2010 at 10:10 Tom GullenTom Gullen 61.7k87 gold badges291 silver badges469 bronze badges 7
  • 4 If you want to write code that runs fast on a mobile processor, yes, you are either going to have to write code in a non-interpreted language, or wait a few years until technology catches up with the exciting pictures in your head. – Paul D. Waite Commented Jul 22, 2010 at 10:56
  • I hope you are not being sarcastic about the 'exciting pictures in my head'! – Tom Gullen Commented Jul 22, 2010 at 11:28
  • 2 A little bit. You seem to think that there’s a lot of scope for JavaScript to perform faster on mobile phones. I doubt Apple’s got much motivation to make web browsing bad on the iPhone. They put a lot of marketing behind apps, but they also market the iPhone as the internet in your pocket. They’re not short of competitors. – Paul D. Waite Commented Jul 22, 2010 at 13:41
  • 1 It's slow compared to traditional computers. But I can't rest my "laptop" on my lap in the summer due to the heat it kicks out, whereas you have to actually leave a running iPad in the sun to make it overheat. It's all trade-offs. iOS is the first commercial attempt I've seen to see just how simple you can make a modern OS whilst still keeping it useful. For now, that means slower JavaScript. – Paul D. Waite Commented Jul 22, 2010 at 22:44
  • 1 Javascript has exactly zero importance if you build your app in Objective-C--which for all intents and purposes is the 'proper' way. The iPhone is incredibly capable. Have you seen it render OpenGL? If you use the right tool for the job, everything will work the way you want it to. If you're trying to make it conform to your own ideals, it's not going to be "capable". If you need to win a drag race, you probably shouldn't try to use a tractor just cause you're a farmer and it's all you've ever known. Just sayin' ;-) – Matt Long Commented Jul 22, 2010 at 22:51
 |  Show 2 more comments

5 Answers 5

Reset to default 9

Javascript is not particularly slow, but the DOM is very slow.
I think it is the same as a desktop browser, but magnified.
I would check first all DOM manipulations, if they can't be optimized.

Another option, is to use a templating engine.
The main DOM manipulations are done through innerHTML injection, which is fast even on mobiles.

We've built a mobile version of our web app, and we use PURE (an open source JS lib we created) to render the HTML from JSON data, and it is very responsive.

We went the HTML5 way(not native) but I think generating the HTML could be done the same way when wrapped in PhoneGap.

I don't think Apple has created any special implementation of Javascript for Mobile Safari. Probably it's the same as or very similar to the desktop Safari.

These devices are small and have strict power constraints, so the CPU is slow.

Apparently iOS won't do JIT compilation of JavaScript (unlike Android) due to a security feature: http://daringfireball.net/linked/2010/07/22/android-ios-js-benchmarks

Good point about DOM access being the issue though: I don't know how much these benchmarks test DOM operations.

@Rudiger: Just a thought - A lot of the improvements to desktop computer speed since "8 years ago" have been attained in part through the use of multiple processors. Javascript is single-threaded, and so presumably would not be able to take advantage of such multiple processors. Yes, I know that browsers can take advantage of it, and that putting the other stuff on the other processors can provide more CPU power to the Javascript thread, but I have an app that is mostly raw Javscript internal processing, where the main thing that is going on is search and array manipulation.

So, when comparing desktop power to mobile processor power, for my purposes, maybe the slowdown would not be so bad? I currently run at very acceptable speeds on Safari on a six-year-old notebook computer with a single processor. So I'm thinking that Safari on iPhone or iPad for me might not be that much worse. Do you think this is reasonable?

Actually, I think Apple has a vested interest in keeping javascript out of the Iphone as much as possible.. they seem to want to regulate things through their appstore by requiring applications that run natively.. I'm curious if javascript is also slow on Android phones, (I've never used one before).. if its not then I think it is a bit strange that the Iphone would be slow with javascript, at any rate, they are already losing market share and will have to address the issue at some point I am sure, I think people are catching on to Apple's games and idiocy in trying to micromanage everything now that more legitimate alternatives are coming out in the mobile device space.

发布评论

评论列表(0)

  1. 暂无评论