简体   繁体   English

Firefox扩展:性能:覆盖与自举

[英]Firefox Extension: Performance: Overlay vs Bootstrapped

I understand the convenience of installing bootstrapped extensions but there is a question that has been bugging me for a long while. 我理解安装自举扩展的方便性,但有一个问题一直困扰着我。

Has there ever been a performance & resource/memory usage comparison between overlay & bootstrapped extensions? 覆盖和引导扩展之间是否有性能和资源/内存使用比较?

In overlay extensions, a lot of the work, ie XUL overlays etc are handled NATIVELY by the application (ie Firefox). 在叠加扩展中,许多工作,即XUL叠加等都由应用程序(即Firefox)进行处理。 In a bootstrapped extension, all above work is left to the extension developer which often involves manually adding many event-listeners and observers to achieve the same (which could be not as native as the applications core). 在引导扩展中,所有上述工作都留给扩展开发人员,这通常涉及手动添加许多事件监听器和观察者以实现相同的目标(可能不像应用程序核心本地化)。

I have noticed startless addons that fail to initiate on occasions on some windows. 我注意到在某些窗口上无法启动的无启动插件。 I have also noticed startless addons that on occasions, the insertion itself was noticeable (ie the functionality, image, icon comes slightly after the window is loaded). 我也注意到了无用的插件,有时,插入本身是显而易见的(即窗口加载后功能,图像,图标稍微有点)。 Furthermore, the type of the even-listener used is not uniform and varies greatly. 此外,所使用的均匀收听者的类型不均匀并且变化很大。

I have a nagging feeling that manually (and not natively) adding menus, context menus, functions, string-bundles, preferences, localization etc and Enumerating windows would use more resources (besides the fact that its efficiency would be greatly dependent on developer's skills). 我有一种唠叨的感觉,手动(而不是原生)添加菜单,上下文菜单,函数,字符串捆绑,首选项,本地化等,枚举窗口将使用更多的资源(除了它的效率将极大地依赖于开发人员的技能) 。

I look forward to your comments :) 我期待你的评论 :)

How an add-on performs mostly depends on the actual implementation (what the add-on does and how) and data it keeps around. 附加组件的执行方式主要取决于实际的实现(附加组件的作用和方式)以及它保留的数据。 As such you cannot really just compare performance of overlay vs. restartless add-ons. 因此你真的不能比较与无需重启附加组件覆盖的性能。

I converted add-ons from overlay to restartless ones that performed better afterwards, because I optimized some things along the way. 我将附加组件从叠加转换为无重启的附加组件,之后表现更好,因为我在此过程中优化了一些功能。 The opposite might be true, of course, in other cases. 当然,在其他情况下,情况恰恰相反。

Memory consumption depends on what the add-on does, incl. 内存消耗取决于附加组件的功能,包括。 how many event listeners it creates. 它创建了多少个事件监听器。 Unless you create thousands upon thousands of event listeners (that also pseudo-leak stuff in closures), the memory consumed by these listeners is usually negligible as about:memory will tell you. 除非你创建成千上万的事件监听器(也就是闭包中的伪泄漏),否则这些监听器消耗的内存通常可以忽略不计:内存会告诉你。 You can have memory hungry overlay add-ons and lightweight restartless add-ons, or vice-versa. 您可以拥有内存饥饿的覆盖加载项和轻量级无重启加载项,反之亦然。

You're right hat the efficiency depends greatly on the skills a developer has, ie the quality of the implementation and data structure designs which is usually directly correlated with said skills. 你的权利很大程度上取决于开发人员的技能,即实施和数据结构设计的质量,这通常与所述技能直接相关。

  • It is easy to create a simple "button" SDK add-on, but the SDK has lots and lots of abstractions to make it easy, and these abstractions consume resources (memory, CPU or even file I/O). 创建一个简单的“按钮”SDK附加组件很容易,但SDK有很多很多的抽象来使它变得简单,而这些抽象消耗资源(内存,CPU甚至文件I / O)。
  • It is a bit harder to create an equivalent overlay add-on, but still you get quite a few things for free ( overlay , style ). 创建一个等效的叠加插件有点困难,但是你仍然可以免费获得很多东西( overlaystyle )。 These niceties are higher-level abstractions, too, and come at a cost. 这些细节也是更高层次的抽象,并且需要付出代价。
  • It is quite difficult to create an equivalent bootstrapped add-on, but if done correctly it might outperform the other add-on types, even during startup (no chrome.manifest to read, parse and interpret, no sync loading of overlays and associated styles, etc.) 创建一个等效的自举附加组件是相当困难的,但是如果正确完成它可能会胜过其他附加类型,即使在启动时也是如此(没有chrome.manifest来读取,解析和解释,没有同步加载叠加和相关样式等)

It's a bit like comparing C (restartless) to Java (overlay) to Ruby (SDK). 这有点像将C(无重启)与Java(覆盖)与Ruby(SDK)进行比较。 People love the convenience of Ruby, but proper Java code easily outperforms it. 人们喜欢Ruby的便利,但正确的Java代码很容易超越它。 Then again, Java will often outperform equivalent C programs written by novice developers (also those novice developers will more likely leak memory all over the place ;), but a C program written by skilled developer may outperform Java. 然后,Java通常会胜过由新手开发人员编写的等效C程序(也是那些新手开发人员更有可能在整个地方泄漏内存;),但是由熟练的开发人员编写的C程序可能胜过Java。

What you're asking here is essentially indicative of premature optimization . 你在这里问的内容基本上表明过早优化 Instead code, measure and then optimize if necessary and according to your skill levels. 而是根据您的技能水平编码,测量然后根据需要进行优化。

Once you notice that your add-on consumes tons of memory or runs slowly, then measure and/or debug the cause. 一旦您注意到您的附加组件消耗大量内存或运行缓慢,则测量和/或调试原因。 Or just measure pro-actively. 或者只是积极主动地衡量。 The point is: measure . 关键是: 衡量

If it isn't your add-on that misbehaves, tell the author, or file a tech evangelism bug if it is real bad. 如果不是你的附加组件行为不端,请告诉作者,或者如果真的很糟糕,请提交技术布道错误

Since you ask about DOM manipulation/overlays, addEventListener vs. "native": 因为你询问DOM操作/覆盖, addEventListener与“native”:

  • Overlays may be faster than calling a bunch of DOM methods from JS. 覆盖可能比从JS调用一堆DOM方法更快。 But then again, overlays are XML and need to be read from disk, then parsed into a DOM, then the DOM needs to be merged with the DOM that is overlaid, following all kinds of rules, etc. That requires all kinds of I/O, (temp.) memory, CPU, etc. So overlays may be slower. 但是再一次,叠加是XML,需要从磁盘读取,然后解析成DOM,然后DOM需要与覆盖的DOM合并,遵循各种规则等。这需要各种I / O,(临时)内存,CPU等。因此叠加可能会更慢。 Depends on the overlay. 取决于叠加层。
  • addEventListener is usually blazingly fast. addEventListener通常非常快。 In fact, overlay "event" listeners, (those nasty oncommand / onclick / onwhatever attributes), use the same implementation internally (well, kinda), and additionally the string values from these attributes will be throw into the JS engine anyway by creating anonymous functions from these strings (and that takes time, too ;) 实际上,覆盖“事件”监听器(那些令人讨厌的oncommand / onclick / onwhatever属性)在内部使用相同的实现(好吧,有点),此外,通过创建匿名,来自这些属性的字符串值将被抛入JS引擎来自这些字符串的函数(这也需要时间;)

Anyway, on the few occasions I actually did measure UI initialization in restartless add-ons (only the DOM stuff in JS) and it always came out taking something in the (lower) double-digit milliseconds range for any add-on with a reasonable amount of DOM and listeners (<100). 无论如何,在少数情况下,我实际上测量了无重启加载项中的UI初始化(只有JS中的DOM内容),并且它总是出现在(较低的)两位数毫秒范围内的任何附加组件中的一些合理的DOM和侦听器的数量(<100)。

BTW: BTW:

I have also noticed startless addons that on occasions, the insertion itself was noticeable (ie the functionality, image, icon comes slightly after the window is loaded). 我也注意到了无用的插件,有时,插入本身是显而易见的(即窗口加载后功能,图像,图标稍微有点)。

Yeah, some restartless add-ons eg load (toolbarbutton) images asynchronously, or delay (some) of their initialization to a later point (eg why populate the context menu before popupshowing ?). 是的,一些无重启的附加组件,例如异步加载(toolbarbutton)图像,或者将它们的初始化延迟(一些)到以后的点(例如,为什么在popupshowing显示之前填充上下文菜单?)。 This can be a little bit less efficient (because it can cause redraws) or can be more efficient (because the browser can continue to execute other initialization code while eg images load in the background). 这可能效率稍低(因为它可能导致重绘)或者可能更有效(因为浏览器可以继续执行其他初始化代码,例如图像在后台加载)。

If restartless add-ons fail to initialize, then well, that is a bug. 如果无重启的加载项无法初始化,那么这就是一个错误。 But I did mention that restartless add-ons are rather difficult to write already. 但我确实提到过不重新启动的附加组件已经很难编写了。

PS: Gecko Profiler and about:memory are your friends ;) PS: Gecko Profilerabout:memory是你的朋友;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM