JavaScript 扩展和 NPAPI 插件在性能方面的差异
我编写了一个无窗口 NPAPI 插件,它绑定到共享库以访问我的本机资源。该插件由在 Firefox 浏览器中运行的 Web 应用程序加载。 最近,我在net上看到,使用Java Script扩展,也可以进行本地代码函数调用。但是这些Java Script扩展是特定于浏览器的。
有人可以告诉我,如果我使用 Java 脚本扩展而不是 NPAPI 插件来调用我的本机代码,在进行本机库 API 调用的延迟方面是否会有任何性能改进?
请注意:我的查询是通用的,并非专门针对 Firefox 浏览器。
I have written a windowless NPAPI plugin which binds to a shared library for accessing my native resources. The plugin is loaded by a web Application running in Firefox browser.
Recently, I have seen in net, that using Java Script extensions, one can also make native code function calls.But these Java Script extensions are specific to browsers.
Can some one please tell me that if I use a Java Script extension instead of NPAPI plugin for calling my native code, will there be any performance improvement in terms of latency in making native library API calls?
Kindly note: My query is generic and not specifically for Firefox browser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于这样的问题没有通用的答案,不同浏览器实现的机制没有任何共同点。
Firefox:可以通过 js-ctypes 调用本机库。这种机制应该比与 NPAPI 插件的通信更轻量。更重要的是,您没有进程间通信的开销(较新的 Firefox 版本在单独的进程中运行插件)。
Chrome:据我所知,访问操作系统功能(例如将文件写入磁盘上的随机位置)的唯一方法是通过 NPAPI,Chrome 不允许扩展程序使用系统库。但是,如果您仅使用本机库来加快执行速度,并且不介意将此代码在沙箱中运行 - 本机客户端可能适合您。由于沙盒执行,它可能会比 NPAPI 插件慢,但安装扩展时不会触发巨大的可怕警告。
Safari:据我所知,Safari 不允许您使用本机库,甚至不通过 NPAPI 插件。
Internet Explorer:从 MSIE 9.0 开始,Internet Explorer 仍然没有任何类似于基于 JavaScript 的扩展。
There is no generic answer to a question like this, the mechanisms implemented by different browsers have nothing in common.
Firefox: A native library can be called via js-ctypes. This mechanism should be more light-weight than the communication with an NPAPI plugin. Even more importantly, you don't have the overhead of inter-process communication (newer Firefox versions run plugins in separate processes).
Chrome: AFAIK the only way to access operating system functionality (such as writing files to a random location on disk) is via NPAPI, Chrome won't allow extensions to use system libraries. However, if you use a native library only to speed up execution and don't mind having this code run in a sandbox - the native client might work for you. Due to sandboxed execution it will probably be slower than an NPAPI plugin but it won't trigger huge scary warnings when your extension is installed.
Safari: From what I know, Safari doesn't let you use native libraries, not even via NPAPI plugins.
Internet Explorer: As of MSIE 9.0, Internet Explorer still doesn't have anything resembling JavaScript-based extensions.