高CPU使用量的JavaScript - 如何调试? [英] High CPU usage of javascript - How to debug?

查看:156
本文介绍了高CPU使用量的JavaScript - 如何调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找到高cpu使用javascript的原因的最好方法是什么?

What is the best way to find the cause of high cpu usage of javascript?

我有一个脚本,只需从缩略图库中的flickr加载照片即可。加载完毕后,没有任何事情正在进行(等待您点击它们显示在Lightbox中),但是cpu的使用率仍然是25%以上。

I have a script that simply loads photos from flickr in a thumbnail gallery. After they're loaded, nothing is being done (waiting for you to click them to display in a lightbox), but the cpu usage is still 25% or more.

我已经打开firebug,点击的配置文件,等一下再次点击它,但它说没有活动要报告。如果有事情发生,不会报告吗?还是我用这个工具错了?

I've opened firebug, clicked profile, waited a bit then clicked it again, but it says "No activity to report". If there was something going on, wouldn't it report? Or am I using this tool wrong?

我在一切都加载完成后,只是为了看看可能会导致高CPU使用率。

I am doing this after everything is loaded, just to see what might be causing that high cpu usage.

谢谢,
Wesley

Thanks, Wesley

编辑:似乎已经跟踪它的起源..这不是任何JS相关,但CSS!这是什么?

问题是这样的:

我有一个缩略图库,我在加载图像时显示加载指示符而不是缩略图:

I have a thumbnail gallery, I display a loading indicator instead of the thumbnail whilst the image is loading:

.thumbnail img {
   display:block;
   background-image: url("/images/ajax-loader.gif");
   background-position: center center; 
   background-repeat:no-repeat;
   overflow:hidden;
   color:white;
}

如果我删除此代码,cpu使用率将下降到0,03%或有些东西..而不是20%...这是因为GIF还在玩,但只是掩盖了吗?

If I remove this code, the cpu usage drops to 0,03% or something.. instead of 20%... Is this because of the animated gif that is still playing, but just covered up?

我不知道动画GIF从cpu这么多?当然,这是做了20多次,但仍然。在Safari / Chrome中也是一样。

I did not know that animated gifs take this much from the cpu? Granted, it's doing that more than 20 times, but still. It was the same in safari/chrome as well.

我想我不应该使用每个图像内的加载指示器,也可以删除背景图像成功加载图像..

I guess I should either not use the loading indicator thing inside of each image, or remove the background-image on a successful load of the image..

推荐答案

我在过去几周使用了工具dynaTrace AJAX版(免费工具)用于分析网站(不仅JavaScript)。它有一些很好的视图,显示资源的使用。尝试跟踪部分JavaScript(或浏览器的其他部分),这是高CPU使用的原因。但是,该工具只能使用Firefox和当前的Internet Explorer实现,但是当您使用firebug时,这似乎表明您正在使用firefox。

I have used over the last weeks the tool "dynaTrace AJAX Edition" (free tool) for analyzing web sites (not only JavaScript). It has some pretty good views that show the usage of resources. Give it a try to track down the part of the javascript (or other parts of the browser) that are the reason for high cpu usage. However the tool is only working with firefox and current internet explorer implementations, but when you use firebug, that seems to indicate that you are using firefox.

他们的论坛页面名为还有什么可以影响浏览器CPU使用率和AJAX性能? ,这给了一些可能有帮助的提示。

There is an entry on their forums page named "What else can impact Browser CPU Usage and AJAX Performance?" which gives some more hints that may help.

这篇关于高CPU使用量的JavaScript - 如何调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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