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.
我一直在研究为iPhone编写应用程序。我非常喜欢PhoneGap的外观,它基本上允许您在应用程序中包含一个网页。我的技能主要是在HTML / Javascript中,因此这个工具可以让我充分利用我的技能,而无需花费很多时间学习如何为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!
我一直在iPhone上为Javascript做一些测试,一些看似简单的例子运行得很慢。真的很慢。不幸的是,这对我的任务来说是个大问题!
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?)
解释为什么Apple似乎创建了如此糟糕的Javascript实现也很有意思(可能会赚更多的钱?更少的网络应用程序=商店中更多的应用程序?)
References
参考
http://ajaxian.com/archives/ipad-javascript-shockingly-slow
http://ajaxian.com/archives/ipad-javascript-shockingly-slow
5 个解决方案
#1
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.
Javascript并不是特别慢,但DOM非常慢。我认为它与桌面浏览器相同,但放大了。如果无法优化,我会首先检查所有DOM操作。
Another option, is to use a templating engine.
The main DOM manipulations are done through innerHTML injection, which is fast even on mobiles.
另一种选择是使用模板引擎。主要的DOM操作是通过innerHTML注入完成的,即使在移动设备上也是如此。
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.
我们已经构建了我们的Web应用程序的移动版本,我们使用PURE(我们创建的开源JS库)来呈现来自JSON数据的HTML,并且它非常敏感。
We went the HTML5 way(not native) but I think generating the HTML could be done the same way when wrapped in PhoneGap.
我们采用HTML5方式(不是本机方式)但我认为生成HTML可以在PhoneGap中包装时以相同的方式完成。
#2
3
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.
我认为Apple没有为Mobile Safari创建任何特殊的Javascript实现。可能与桌面Safari相同或非常相似。
These devices are small and have strict power constraints, so the CPU is slow.
这些设备很小并且具有严格的功率限制,因此CPU很慢。
#3
2
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
显然,由于安全功能,iOS不会对JavaScript进行JIT编译(与Android不同):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.
关于DOM访问的好处是问题:我不知道这些基准测试多少测试DOM操作。
#4
0
@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.
@Rudiger:只是一个想法 - 自“8年前”以来,台式计算机速度的许多改进部分是通过使用多个处理器来实现的。 Javascript是单线程的,因此可能无法利用这样的多处理器。是的,我知道浏览器可以利用它,并且将其他处理器放在其他处理器上可以为Javascript线程提供更多的CPU能力,但我有一个应用程序,主要是原始的Javscript内部处理,其中主要的事情是正在进行的是搜索和数组操作。
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?
那么,在将桌面电源与移动处理器电源进行比较时,就我的目的而言,放慢速度可能不会那么糟糕?我目前在Safari上使用单处理器以六年历史的笔记本电脑上以非常可接受的速度运行。所以我认为iPhone或iPad上的Safari对我来说可能不会那么糟糕。你认为这是合理的吗?
#5
-1
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.
实际上,我认为Apple尽可能地保持javascript不受Iphone的影响。他们似乎想要通过他们的appstore通过要求本地运行的应用程序来管理事物..我很好奇,如果javascript也很慢Android手机,(我之前从未使用过一款)..如果不是那么我觉得有点奇怪的是Iphone会慢慢用javascript,无论如何,它们已经失去了市场份额而且必须解决问题在某些方面,我确信,我认为人们正在抓住Apple的游戏和白痴试图微观管理一切,因为移动设备领域出现了更多合法的替代品。
#1
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.
Javascript并不是特别慢,但DOM非常慢。我认为它与桌面浏览器相同,但放大了。如果无法优化,我会首先检查所有DOM操作。
Another option, is to use a templating engine.
The main DOM manipulations are done through innerHTML injection, which is fast even on mobiles.
另一种选择是使用模板引擎。主要的DOM操作是通过innerHTML注入完成的,即使在移动设备上也是如此。
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.
我们已经构建了我们的Web应用程序的移动版本,我们使用PURE(我们创建的开源JS库)来呈现来自JSON数据的HTML,并且它非常敏感。
We went the HTML5 way(not native) but I think generating the HTML could be done the same way when wrapped in PhoneGap.
我们采用HTML5方式(不是本机方式)但我认为生成HTML可以在PhoneGap中包装时以相同的方式完成。
#2
3
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.
我认为Apple没有为Mobile Safari创建任何特殊的Javascript实现。可能与桌面Safari相同或非常相似。
These devices are small and have strict power constraints, so the CPU is slow.
这些设备很小并且具有严格的功率限制,因此CPU很慢。
#3
2
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
显然,由于安全功能,iOS不会对JavaScript进行JIT编译(与Android不同):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.
关于DOM访问的好处是问题:我不知道这些基准测试多少测试DOM操作。
#4
0
@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.
@Rudiger:只是一个想法 - 自“8年前”以来,台式计算机速度的许多改进部分是通过使用多个处理器来实现的。 Javascript是单线程的,因此可能无法利用这样的多处理器。是的,我知道浏览器可以利用它,并且将其他处理器放在其他处理器上可以为Javascript线程提供更多的CPU能力,但我有一个应用程序,主要是原始的Javscript内部处理,其中主要的事情是正在进行的是搜索和数组操作。
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?
那么,在将桌面电源与移动处理器电源进行比较时,就我的目的而言,放慢速度可能不会那么糟糕?我目前在Safari上使用单处理器以六年历史的笔记本电脑上以非常可接受的速度运行。所以我认为iPhone或iPad上的Safari对我来说可能不会那么糟糕。你认为这是合理的吗?
#5
-1
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.
实际上,我认为Apple尽可能地保持javascript不受Iphone的影响。他们似乎想要通过他们的appstore通过要求本地运行的应用程序来管理事物..我很好奇,如果javascript也很慢Android手机,(我之前从未使用过一款)..如果不是那么我觉得有点奇怪的是Iphone会慢慢用javascript,无论如何,它们已经失去了市场份额而且必须解决问题在某些方面,我确信,我认为人们正在抓住Apple的游戏和白痴试图微观管理一切,因为移动设备领域出现了更多合法的替代品。