English 中文(简体)
为什么HTML/Web用户界面反应慢于本地用户界面反应?
原标题:Why HTML/Web UI response slower than Native UI?

我不明白为什么HTML/Web UI的反应比WinForms/WPF/Android View/Native UI反应慢?

土著UI还拥有网络UI的风格、元素巢穴、事件,比CSS、DOM、喷射事件还要多。

事件反应时间包括:焦点改变、下降、滚动、动画移动、动画调整等。

DOM树插入/替换速度也较慢,插入10 000焦耳 html将花费100毫秒的谷歌铬和机器人4.0,而解析其模板只花费20毫秒(jQuery微型模板)。

减速事件反应的最大因素或许是:

  1. The UI locking between parallel javascript processes;
  2. The rendering engine is too slow to process the new UI changing messages from javascript workers, especially when the browser rendering engine is busy with the last UI updating(because of the point 3);
  3. The html layout method (for example: css cascading, inline flow layout, responsive layout etc) may slow down partial UI updating.
  4. Parsing html/xml cost long time, a hint: Android view inflation relies heavily on pre-processing of XML files that is done at build time(http://developer.android.com/reference/android/view/LayoutInflater.html)

HTML 和 CSS 标准的子集或许是未来开发 Webview appp 的解决方案:

http://www.silexlabs.org/haxe/cocktail/

http://www.terrainformatica.com/htmlayout/" rel="noreferrer" >http://www.terrainformatica.com/htmlayout/

http://www.nativecs.com/" rel="noreferrer" >http://www.nativecs.com/

http://www.pixate.com/" rel="noreferrer" >http://www.pixate.com/

https://github.com/tombenner/nui" rel=“noreferrer'>https://github.com/tombenner/nui

http://steelratstory.com/steelrat-products/wrathwebkit> rel=“noreferrer'>http://steelratstory.com/steelrat-products/wrathwebkit

http://trac.webkit.org/wiki/EFLWebKit

https://github.com/WebKitNix/webkitnix

http://qt-project.org/doc/qt-4.8/richtext-html-subset.html

http://sealedabstract.com/rants/ why-mobile-web-aps-aps-aps-are-slow/" rel="noreferr" >http://sealedabstract.com/rants/ why-moble-web-aps-aps-aps-slow/

一组本地UI标记语言:http://en.wikipedia.org/wiki/User_interface_markup_language

为什么没有简化的HTML标准和简化的Webcore布局引擎来取代这些本地 UIML?

也许我们可以在kivy.org项目中发现一个子集 html。

PC, 和机器人浏览器 = 应用程序线 + ui 线

iOS 浏览器 = 应用程序线 + ui 数据线 + ui 硬件线 (Core Aimpation/ OpenGL ES)

在 ios 浏览器中, 应用程序线索可以直接调用 ui 硬件线索 。

问题回答

如果JavaScript在客户端完全执行网络界面, 与 WinForms/ Native UI 的区别将微不足道。

然而,在多数情况下,网络界面会触发网络服务器的某些网络请求,然后它必须经过以下步骤才能达到与WinForms/Native application相同的效果:

  1. Send a HTTP request (GET/POST/...) to the Web server
  2. The Web server is an executable (in the format of an external app or a service) listening to one or multiple ports. When it receives the request, parses it, and finds the Web application.
  3. Web server executes backend (server-side) logic within application.
    Web application such as ASP.NET is pre-compiled. Time complexity of this step could be very close to a Windows app.
  4. Web server renders the result into markup and sends it back to the client
  5. Client (Browser) parses the result and updates the UI if necessary. Controls/images/other resources in a Web page normally take a little longer to render within a browser than a Windows app renders its display.

即使网络服务器是本地的,也不能忽视数据解析/格式化/传输产生的成本。

On the other hand, an application with WinForms/Native UI typically maintains a message loop, which is active and hosted in machine code. A UI request normally just triggers a lookup in the message table and then execute the backend logic (Step 2 in the above)
When it returns result and updates UI, it can be simply binary data structure (doesn t need to be in markup), and doesn t reply another application(browser) to render to the screen.

最后,WinForms/Natima 应用程序通常拥有全部控制权,可以维持多个线索,以逐步更新UI,而网络应用程序对这种类型的服务器侧资源没有直接控制权。

UPDATE :
当我们比较网站应用程序和Windows/WPF(或原生)应用程序时,它们使用相同的网络服务来部分更新它们的 UI

""https://i.sstatic.net/939c1.png" alt="此处的内置图像描述"/"

The two UIs should respond and refresh with ignorable speed difference. The implementation difference between binary & scripting execution to respond and refresh UI is almost nothing.
Neither of the UIs needs to reconstruct the control tree and refresh entire appearance. Given same conditions, they could have same CPU priority, memory/virtual memory caching, and same/close number of kernel object & GDI handles at process/thread level.
In this case, as you described, there should be almost no visual difference.

UPDATE 2:
Actually event handling mechanisms in Web and Windows apps are similar. DOM has event bubbling. Similarly, MFC has command routing; Winforms has its event flow; WPF has event bubbling and tunnelling, and so on. The idea is a UI event might not strictly belong to one control and a control has some way to claim an event has been "handled". For standard controls, focus changing, text changing, dropdown, scrolling events should have similar client-side response time for both Web and Windows apps.

从性能上看, 图像是最大的差异。 网络应用程序对“ 设备上下文” 的控制有限, 因为一个网页是由外部应用程序 — — 网络浏览器 — — 托管的。 Windows 应用程序可以使用像 WPF 这样的 GPU 资源来实施动画效果, 并通过部分刷新“ 设备上下文” 来加速生成。 这就是为什么 HTML5 画布让网络开发者在 Windows 游戏开发者使用 OpenGL/ DirectX 超过 10 年的时间里很兴奋 。

UPDATE 3:
Each Web browser engine (http://en.wikipedia.org/wiki/Layout_engine) has its own implementation of rendering DOM, CSS; and implementation of (CSS) selectors. Moving and resizing elements within a Web page is changing DOM, CSS (tree) setup. The selector and rendering performance highly depends on the Web browser engine.

  1. UI operations could make selectors go through unnecessary steps to update UI.
  2. A Web page doesn t have control to inform the browser to do partial rendering.

使高档 JavaScript 控制( 一些jQuery UI、 dojo、Ext JS) 无法实时快速, 通常比 Flash 控制慢 。

客户花在客户身上的时间与数据在网络上运行的时间相比是微不足道的。 浏览器中Windows 窗体或网页的实际转换时间以微秒( 十分或几百秒) 测量。 向服务器发送请求并获取结果以毫秒计量 。

你可以轻而易举地确认这一点:

  1. Create a simple Winforms application, time it.
  2. Create a similar Web-based application. Run it on the webserver on your own PC, I.E. //localhost/myapp.asp and time it.
  3. Run it on a remote webserver and time it.

你可以看到,1是最快的,后面是2(稍慢一点,解释 HTML, CSS 等),而3则由于网络时间而大大放慢。

为了回答你的问题,几乎完全是由于网络延误造成的差别,网络延误比当地处理时间要大得多。

加入一个解释原因的评论,

3个大差异

  1. WebUI 应用程序在一个浏览器内运行,然后取决于浏览器的优化程度。

  2. 浏览器还有自己的javascriptjvm。 在运行代码之前必须运行和解释该代码的另一个过程 。

所有这些都是在本地 OS 上方的额外层。 如果您在浏览器中提出您计算机的活动监视器, 并在浏览器中建立网页, 您将会注意到资源鼠网络浏览器是什么 。

  1. Native UI elements have graphics acceleration support. depending on the os, native ui templates are compiled to a native format that does not have to be parsed for rendering.

要记住的一件事是,浏览器本身是一个本地应用程序, 所以任何为浏览器运行而建造的东西, 都必然会用(至少)额外的一个抽象层来写, 而不是直接为本地执行而写的东西。

值得一提的还有:

300ms tap delay, gone away http://updates.html5rocks.com/2013/12/300ms-tap-delay-gone-away

造成这种人为拖延的最初动力是支持捏-断层和其他触摸互动 -- -- 也就是说,本案反应迟缓是故意使不同的用户行动脱钩的一种方式。

虽然这是一个相当具体的使用案例,但一般概念确实作为基于浏览器的与本地执行的不同考虑的一个例子,即基于浏览器的经验包括解决各种互动和内容的一些通常的框架成本,而本地经验则自然更具体地专门针对仅仅倾听/响应所希望的互动模式。

在整个实施过程中,许多细小的部分(如这种部分)比较细小,而且重点更集中在原始本本中,这有助于提高反应能力的总体效果。

只有低于标准的浏览器(这包括所有安道尔浏览器、所有Mac OS浏览器、所有Linux浏览器,以及所有版本最差的Google Chrome ) 。 这些浏览器写得不好,没有优化,没有触摸屏幕延缓度、UI反应和平稳滚动。 在任何 CPU 活动、 磁盘或网络 I/ O 和用户输入中,它们都会锁住并结结巴。

互联网探索者11或iOS Safari等高级浏览器有时比未优化的本地应用程序反应更灵敏。

基本上只有 Windows 8.1 和 iOS 有反应性浏览器。 所有其他浏览器在用户界面响应性方面都低劣。 差别非常大 。 IE11 和 iOS Safari < commend > obliterate 其它浏览器在 UI 延缓和平滑中。





相关问题
How to start to create an application GUI using C#?

HI! I am new to C# and plan to use it for my application GUI. I am trying to make my GUI similar to SPSS:http://www.spss.com/images/08/statistics_screens/ez_rfm-big.jpg Is this easy in C#? Is there ...

Automatic height of edit box

My shoes application has three items stacked on top of each other (with a stack, of course), in order: A banner An edit box Two buttons in a flow What I want to do is have the banner stay at it s ...

Search by using the keyboard in a list/grid - algorithm

I need to implement a custom search in a grid and I would like to find some user interface guidelines that explain the standard way to implement it. I mean this kind of search that is initiated by ...

UI And TcpClient Issue in vb.net

I m having some problems with a small ircbot i m writing. Basically I connect to the server using a tcpclient in a seperate class, which also runs on its own thread. I want to display the server text ...

UI Convention: Shortcut key for application exit? [closed]

Is there a convention for the shortcut keys for application exit? Some applications uses Alt+X some others use Ctrl+ X and Ctrl+Q. Applications like FF and IE doesnot assign a shortcut at all. So is ...

热门标签