我正在使用Javascript解析一个包含大约3,500个元素的XML文件.我正在使用jQuery"each"函数,但我可以使用任何形式的循环.
问题是浏览器在循环执行时冻结了几秒钟.在不降低代码速度的情况下停止冻结浏览器的最佳方法是什么?
$(xmlDoc).find("Object").each(function() {
//Processing here
});
Run Code Online (Sandbox Code Playgroud) 我正在进入2D/3D图形项目,我面临性能问题.
我的算法采用两个图像:图片和相对灰度深度图.我还有一个10个画布("图层")的数组,最初是空白的.注意:所有图像都具有相同的尺寸.
我需要检查深度图的每个像素X; Y,并根据其颜色值,访问10个画布中的一个,并在其上绘制原始图像的X; Y像素.
结果算法有点像:
for (var y = 0; y < totalHeight; ++y) {
for (var x = 0; x < totalWidth; ++x) {
var index = (y * totalWidth + x) * 4; // index of the current pixel
// parse depth level using luminosity method
var depthLevel = Math.round(
0.21 * depthData[index] +
0.71 * depthData[index + 1] +
0.07 * depthData[index + 2]
);
// get the proper layer to modify
var layerIndex = Math.floor((layersCount …Run Code Online (Sandbox Code Playgroud)