Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript performance: How to check what is slowing down the page?

I have a page which is very slow, not in loading, but in terms of the responsiveness of typing into the form fields on the page.

There is no ajax on the page - this is nothing to do with network transport.

What are good strategies for discovering where the code bottlenecks are? I have found nothing in the chrome developer tools to tell me where the bottlenecks are.

like image 754
Marcin Avatar asked Dec 04 '11 16:12

Marcin


People also ask

How do I troubleshoot JavaScript performance issues?

Google Chrome's DevTools is one of the best ways to measure JavaScript performance and debug any bottlenecks. You can open DevTools by running Google Chrome and then pressing Command+Option+I (Mac) or Control+Shift+I (Windows & Linux), or even just right-click and select Inspect.

Why is my JavaScript slow?

Any more than 200 ms load time is a major red flag. If you find a slow JavaScript file that is hosted on your site (rather than from a third party) then you can take steps to compress and minify the JavaScript to make it load faster. Another trait to look for is what we call a “chatty” asset.

What is performance in JavaScript?

In JavaScript performance. now() method can be used to check the performance of your code. You can check the execution time of your code using this method. It returns the value of time (of type double) in milliseconds. The returned value represents the time elapsed since the execution started.


2 Answers

It sounds to me like you have some event firing on each key press on you input field. Things you can do :

  1. If Chrome's profiler doesn't fit your needs, try FireBug or IE9's profiler which is quite decent. In IE9 you can see how much CPU time was spent on each function call.
  2. Temporarily remove the handlers from the fields, one by one, and observe any changes in the performance.

Let me know how it goes!

like image 87
Boris Jockov Avatar answered Nov 15 '22 15:11

Boris Jockov


Webkit has a 'profile' option. Open the developer tools (ctrl+shift+i) and click on 'Profiles'. From there you can see a record button (the circle) at the bottom. Click it and use your page as you normally would. Click it again to stop and inspect your timelines for your function calls!

Alternatively you can benchmark functions individually using:

console.time( "Some label" );
console.timeEnd( "Some label" );
like image 42
KeatsKelleher Avatar answered Nov 15 '22 14:11

KeatsKelleher