最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

debugging - Finding bottlenecks in javascript? - Stack Overflow

programmeradmin1浏览0评论

I'm attempting to find a bottleneck in my Javascript. Basically I'm developing a chrome extension written in Javascript which is taking 4-5 seconds to perform a task. There's a lot of code involved in the task and using print statements / chrome built in dev tools just isnt working. The dev tools don't seem to even see my Javascript running. I'm wondering if anyone has any advice / tools they think could be of benefit?

I'm attempting to find a bottleneck in my Javascript. Basically I'm developing a chrome extension written in Javascript which is taking 4-5 seconds to perform a task. There's a lot of code involved in the task and using print statements / chrome built in dev tools just isnt working. The dev tools don't seem to even see my Javascript running. I'm wondering if anyone has any advice / tools they think could be of benefit?

Share Improve this question asked Jan 24, 2011 at 15:05 SkizitSkizit 44.9k93 gold badges213 silver badges270 bronze badges 3
  • 1 We need more information. What task are you performing? Can you give us code listings of the inner loops? Usually, greater performance increases are obtained with better algorithms. Tell us what you're trying to accomplish and how you're trying to accomplish it and maybe we can help more. – Sparafusile Commented Jan 24, 2011 at 15:32
  • it is a chance that the code isn't running because you uses setTimeout and such. Try to use Timeline to look what really happens. – loislo Commented Jan 25, 2011 at 8:03
  • Yes, I've seen that an injected content script is very hard to debug and profile because the JS environment is separate from the webpage's and the inspector can't even see the JS script. I don't know any good workarounds yet. – yonran Commented Jan 25, 2011 at 9:54
Add a comment  | 

4 Answers 4

Reset to default 10

Open your page in Chrome.

Tools -> Developer tools -> Profiles

Start Profiling (3rd button, grey circle on the status bar at the bottom)

Perhaps it'd be a good idea to open the HTML files in Firefox instead of letting Chrome extensions handle it. That'd allow you to use Firebug to determine any causes, which would be very helpful.

I remember Google Chrome has a built-in JavaScript profiler. Or can't you use this for your extension? (I have never built Chrome extensions.)

You can try to use Profiler as it was mentioned before or Timeline. Timeline will help you if the time was spent in native code.

发布评论

评论列表(0)

  1. 暂无评论