网站工作人员处理Ajax调用 - 优化大材小用? [英] Web Workers handling AJAX calls - optimisation overkill?

查看:95
本文介绍了网站工作人员处理Ajax调用 - 优化大材小用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正与一个code处理使用的Web Workers(可用时)所有的AJAX请求。这些工人做的比 XMLHtt prequest 对象处理(没有额外计算),几乎什么都没有了。工人创造的所有请求都是异步的( request.open(获取,网址,真实))。

I'm working with a code that handles all AJAX requests using Web Workers (when available). These workers do almost nothing more than XMLHttpRequest object handling (no extra computations). All requests created by workers are asynchronous (request.open("get",url,true)).

最近,我得到了几个关于这个code问题,我开始怀疑我是否应该花时间来修复这个或只转储的整体解决方案。

Recently, I got couple of issues regarding this code and I started to wonder if I should spend time fixing this or just dump the whole solution.

我的研究,到目前为止表明,这code可实际上损害的表现。但是,我没能找到支持这一任何可靠的消息来源。我只有两个结果是:

My research so far suggests that this code may be actually hurting performance. However, I wasn't able to find any credible source supporting this. My only two findings are:

  • 2岁的 jQuery的功能,建议利用网络工作者的AJAX调用
  • <一个href="http://stackoverflow.com/questions/14068084/opinion-about-synchronous-requests-in-web-workers">this SO问题似乎问的东西有点不同(使用网络工作者同步请求VS AJAX调用)
  • 2 year old jQuery feature suggestion to use web workers for AJAX calls
  • this SO question that seems to ask about something a bit different (using synchronous requests in web workers vs AJAX calls)

有人点我到一个可靠的来源讨论这个问题?或者,是否有任何的基准,可能打消了我的疑虑?

Can someone point me to a reliable source discussing this issue? Or, are there any benchmarks that may dispel my doubts?

[修改]更多的时候WebWorker还负责分析的结果有趣的这个问题得到一点点(JSON.parse <$ C C $>)。是异步解析提高性能?​​

[EDIT] This question gets a little bit more interesting when WebWorker is also responsible for parsing the result (JSON.parse). Is asynchronous parsing improving performance?

推荐答案

我创建了一个适当基准上jsperf 。根据不同的浏览器, WebWorker方法是慢85-95%不是原始的AJAX调用。

I have created a proper benchmark for that on jsperf. Depending on the browser, WebWorker approach is 85-95% slower than a raw ajax call.

注:

  • ,因为网络响应时间可以为每个请求的不同,我只测试新XMLHtt prequest() JSON.parse (jsonString); 。有没有的真正的AJAX调用正在进行。
  • WebWorker安装和拆卸操作的不可以被测量
  • 请注意,我测试的一个请求,结果webworker方法可能是多个同时请求
  • 更好
  • 在卡尔文梅特卡夫​​向我解释,在jsperf比较同步和异步不会给准确的结果和他创造的另一个标杆,消除异步开销。结果仍然显示WebWorker方法是显著慢。
  • reddit的讨论我了解到,主页,WebWorker之间传递的数据被复制并在此过程中被序列化。因此,使用WebWorker仅供解析没有太大的意义,数据将被序列化和反序列化反正之前,你可以使用他们的主页上。
  • since network response time can be different for each request, I'm testing only new XMLHttpRequest() and JSON.parse(jsonString);. There are no real AJAX calls being made.
  • WebWorker setup and teardown operations are not being measured
  • note that I'm testing a single request, results for webworker approach may be better for multiple simultaneous requests
  • Calvin Metcalf explained to me that comparing sync and async on jsperf won't give accurate results and he created another benchmark that eliminates async overhead. Results still show that WebWorker approach is significantly slower.
  • From the Reddit discussion I learned that data passed between the main page and WebWorker are copied and have to be serialized in the process. Therefore, using WebWorker for parsing only doesn't make much sense, data will have to be serialized and deserialized anyway before you can use them on the main page.

这篇关于网站工作人员处理Ajax调用 - 优化大材小用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆