Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 Application reacting very slowly only while Chrome DevTools is open

My Angular 2 Application is slow to respond (1-5 seconds) to key input, button clicks, tabbing across inputs, etc. only when Chrome Developer Tools is open. Material 2 animations also become slow and choppy.

I've been developing this application for three months, and use Chrome DevTools every day. This issue cropped up seemingly overnight.

What I know:

  • I stashed all pending application changes to revert my application to a time when this was not a problem. The issue persisted.
  • Chrome DevTools doesn't seem to slow down any other application (ie. google inbox, google maps) in the same browser session.
  • Maddeningly, when I run the DevTools' Timeline "Record" to try to gain visibility into the issue, the issue disappears and the page reacts at normal speed again! I assume this is the best clue that I have, but I don't know the internal workings of DevTools well enough to know how "Timeline Record" changes things.
  • I've restarted Chrome and deleted all cached data.
  • Nothing of the sort happens in Firefox or IE when I open the Developer tools in those.

Any recommendations on where to look next would be greatly appreciated!

like image 940
Daniel Patrick Avatar asked Sep 23 '16 14:09

Daniel Patrick


People also ask

Why is my Angular app so slow?

If you've done your research and figured out that your app doesn't render that much and doesn't render that often, then your code may just simply be quite slow. This is probably due to some heavy scripting and not DOM-related. Use WebWorkers. The Angular CLI also provides a command to generate a WebWorker in a snap.

How do I check my DevTools performance?

To access the Performance tab, navigate to the website you want to profile, then open Chrome DevTools by right-clicking and selecting Inspect. Select the Performance tab inside Chrome DevTools. The easiest way to capture a performance profile is by clicking the Start profiling and reload page icon.


2 Answers

Final answer:

Remove all breakpoints

enter image description here

Even if they're not getting hit this fixed it for me and got performance back to normal.

May be a bigger issue if you have logging breakpoints - so try deleting those first if you're attached to your breakpoints.


Previous answers:

I came up with a workaround - although still not really figured out what is actually wrong.

I also discovered a bunch of tools I didn't even know existed that I'd skipped over before - they're under More tools.

Start by opening the Performance Monitor. This shows a nice CPU graph isolated for your Chrome tab - the Windows task manager is as useless as it ever was.

enter image description here

This is the behavior I got when choosing a date from mat-calendar. No other logic running - just selecting a date. I removed everything from app-component and just put a mat-calendar and it took ten seconds to change the date!

Other controls are generally fine. I could open dialogs, use combo boxes etc. and nice and fast. But selecting a date gave me this nonsense:

enter image description here

I tried emptying local storage, clearing cache, etc. and then I changed port number for my website. I simply changed dev.example.com:44300 to dev.example.com:44301 - in other words Chrome now thought it was a different website.

This is what it looked like after I switched port number.

enter image description here

I also got the same effect using a reverse proxy server - which put my local machine on the internet - so I could try to duplicate the issue from other machines. I could not.

So hope that helps someone - still no clue what's in the cache for this server that is having such a massive impact on performance. But for sure it's not just my code.


Here's a few other things to try:

Test with --aot flag

This didn't make a difference to me, but good to narrow things down.

Add some controls that don't do anything (as a control)

This way you can find if some specific action or control is causing the slow down. You should of course be able to toggle these instantly.

Just toggle them on and off, hide something.

<mat-radio-group>
    <mat-radio-button [value]="false">
        bloop
    </mat-radio-button> 
    <mat-radio-button [value]="false">
        bloop bloop
    </mat-radio-button> 
</mat-radio-group>

Enable Rendering debugging options

enter image description here

Make sure you aren't re-rendering the whole page constantly

The rendering option above will show this to some extent, but one thing I like to do is just add a random text box - type in it and if the text subsequently disappears you know that control has been rerendered.

 <!-- yes, just a standard text box -->
 <input type="text"/>      

Just hide things with *ngIf="false"

Hide controls (yours and third party) and see if anything is causing problems.

For me I'm currently suspecting mat-calendar is causing issues - but I'm still thoroughly confused as to why enabling 'Record' makes the problem non existent.

like image 134
Simon_Weaver Avatar answered Oct 13 '22 16:10

Simon_Weaver


I've fixed the issue, but I'll never know what was causing it. Likely a setting that I had accidentally changed.

I deleted the Chrome App and reinstalled, everything is back to normal. I'm going to leave this question open in case anyone else has this problem or wants to contribute.

like image 38
Daniel Patrick Avatar answered Oct 13 '22 14:10

Daniel Patrick