- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
首先,我自己创建了一个正则表达式,它将匹配项目中所有头文件列表中所有唯一的外部库路径。 I asked a question regarding making that regexp一周前。
我开始四处看看它在异步时以及在变成 Web Worker 时的行为。为了方便和可靠,我创建了这个在所有三种模式下运行的通用文件:
/** Will call result() callback with every match it founds. Asynchronous unless called
* with interval = -1.
* Javadoc style comment for Arnold Rimmer and other Java programmers:
*
* @param regex regular expression to match in string
* @param string guess what
* @param result callback function that accepts one parameter, string match
* @param done callback on finish, has no parameters
* @param interval delay (not actual interval) between finding matches. If -1,
* function will be blocking
* @property working false if loop isn't running, otherwise contains timeout ID
* for use with clearTimeout
* @property done copy of done parameter
* @throws heavy boulders
**/
function processRegex(regex, string, result, done, interval) {
var m;
//Please tell me interpreter optimizes this
interval = typeof interval!='number'?1:interval;
//And this
processRegex.done = done;
while ((m = regex.exec(string))) {
Array.prototype.splice.call(m,0,1);
var path = m.join("");
//It's good to keep in mind that result() slows down the process
result(path);
if (interval>=0) {
processRegex.working = setTimeout(processRegex,
interval, regex, string,
result, done, interval);
// Comment these out for maximum speed
processRegex.progress = regex.lastIndex/string.length;
console.log("Progress: "+Math.round(processRegex.progress*100)+"%");
return;
}
}
processRegex.working = false;
processRegex.done = null;
if (typeof done=="function")
done();
}
processRegex.working = false;
我创建了一个测试文件,而不是将其粘贴到此处,而是将其上传到非常可靠的虚拟主机上:Demo - Test data .
令我感到非常惊讶的是,Web Worker 和浏览器执行 RegExp 之间存在如此显着的差异。我得到的结果:
<strong>[WORKER]:</strong> Time elapsed:16.860s
<strong>[WORKER-SYNC]:</strong> Time elapsed:16.739s
<strong>[TIMEOUT]:</strong> Time elapsed:5.186s
<strong>[LOOP]:</strong> Time elapsed:5.028s
您还可以看到,对于我的特定正则表达式,同步循环和异步循环之间的区别是微不足道的。我尝试使用匹配列表而不是先行表达式,结果发生了很大变化。以下是对旧功能的更改:
function processRegexUnique(regex, string, result, done, interval) {
var matchList = arguments[5]||[];
... same as before ...
while ((m = regex.exec(string))) {
... same as before ...
if (matchList.indexOf(path)==-1) {
result(path);
matchList.push(path);
}
if (interval>=0) {
processRegex.working = setTimeout(processRegex, interval,
regex, string, result,
done, interval, matchList);
... same as before ...
}
}
... same as before ...
}
结果:
<strong>[WORKER]:</strong> Time elapsed:0.062s
<strong>[WORKER-SYNC]:</strong> Time elapsed:0.023s
<strong>[TIMEOUT]:</strong> Time elapsed:12.250s
( self 提醒:每一分钟都变得越来越奇怪)<strong>[LOOP]:</strong> Time elapsed:0.006s
谁能解释速度上的这种差异?
最佳答案
经过一系列测试,我确认这是一个 Mozilla Firefox 问题(它影响我尝试过的所有 windows 桌面版本)。使用 Google Chrome、Opera 甚至 Firefox mobile,无论是否使用 worker,regexp 匹配都大致相同。
如果您需要解决此问题,请务必在 bug report on bugzilla 上投票.如果有任何变化,我会尝试添加其他信息。
关于javascript - WebWorker 计算慢速正则表达式匹配速度明显慢 (3x) - 仅限 firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32910126/
我无法将 wasm.instance.exports 对象发布到 WebWorkers 或从 WebWorkers 发布。任何帮助将不胜感激。 最佳答案 通过 postMessage API 发送的消
我正在使用 webworks 开发 Blackberry 10 App,我想使用 webworks 获取设备 IMEI 号码。我没有找到任何解决方案来在互联网上获取 IMEI 号码。 最佳答案 查看身
我无法使用安装在默认位置的 SDK 来构建 Ripple。我收到错误消息“Oh Snap!Build request failed with message: ./Applications/Black
我曾尝试在 Facebook 上分享,但无法分享任何内容。我使用的代码是:- 在 JavaScript 中 FB.init({ appId: 'some id',
因此,我尝试进行测试,看看 WebWorker 线程 ( https://github.com/audreyt/node-webworker-threads ) 可以在多核系统中使用 NodeJS 改
在网上搜索了很多天后,我从来没有找到我的问题的答案,甚至没有找到任何人设法做我正在尝试的事情。 我正在尝试在 Blackberry 的 WebWorks 应用程序中实现推送通知,但没有任何运气。我尝试
我有一个使用 Javascript 递归函数的第一个版本,它产生了预期的结果。下面是工作版本: // Call the recursive function and get final (a,b) r
我正在尝试从 Ripple 模拟器中打包并签署一个 BlackBerry webworks 应用程序(我也尝试过使用 bbwp)。 打包工作正常,但签名会返回非常有用的错误消息 [ERROR] Sig
调试网络 worker 的最佳方法是什么?我的工作人员似乎在某个地方出现了故障,但我似乎无法将内容记录到控制台来弄清楚发生了什么。有没有办法使用 firebug 或 webkit 的检查器在 webw
我有一个数组,需要将其从 WebWorker 传输回主线程。据我所知,只有 ArrayBuffers 和 TypedArrays 是可传输的,其他任何内容都是复制而不是传输的。 我遇到的问题是数组包含
我一直在研究如何与网络 worker 之间传输数据,我发现的每个示例都显示以下格式: var myData = new Uint8ClampedArray(256); postMessage(myDa
如何将函数(的副本)从我的主线程发送到我的工作线程? 每当我尝试:worker.postMessage({data, func: (data) => data)时,firefox都会给我一条错误消息:
在 WebWorker 中运行的代码是否在不同的 JavaScript 运行时领域中运行? 最佳答案 是的。 Step 6 in the WHATWG spec . Call the JavaScri
这个问题在这里已经有了答案: How to allow Web Workers to receive new data while it still performing computation?
有没有办法在 JavaScript 中破坏 HTML5 WebWorker? 这是我的情况:我有一个 Web 应用程序生成相当数量的 WebWorker(在 16 到 32 之间的任何地方)来优化一些
我一直致力于优化一些长时间运行的 JavaScript,并尝试实现 WebWorkers。 我有一组独立的任务要计算。在我的初始测试中,有 80 个任务,在主线程上用了 250 毫秒完成。我认为我可以
我正在使用 webworks sdk 开发一个剧本应用程序。 我正在尝试通过发送和接收数据来发出 http 请求(方法:发布)。 我可以从服务器获取响应,但是服务器无法获取 $POST 数据,当我尝试
快速提问 如果我有一个 WebWorker有一个返回 Observable 的函数回到UI代码,如果我再订阅Observable,是在UI线程上运行的observable还是WebWorker线? 我
我正在为 Blackberry Playbook 开发一个 WebWorks 应用程序。他们文档中的这个页面说 You can display a specific type of virtual k
任何人都知道是否可以在 Web Worker 中合并一组立方体几何图形并将其传递回主线程?认为这可以减少合并大量立方体时的延迟。 Three.JS 在 Web Worker 中是否可以正常工作,如果可
我是一名优秀的程序员,十分优秀!