Why does Javascript run so slow on iPhone?

前端 未结 5 1469
迷失自我
迷失自我 2021-01-04 12:30

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 i

相关标签:
5条回答
  • 2021-01-04 12:46

    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.

    0 讨论(0)
  • 2021-01-04 12:54

    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.

    0 讨论(0)
  • 2021-01-04 12:57

    @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?

    0 讨论(0)
  • 2021-01-04 13:00

    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.

    0 讨论(0)
  • 2021-01-04 13:05

    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 讨论(0)
提交回复
热议问题