addons-code-manager icon indicating copy to clipboard operation
addons-code-manager copied to clipboard

Loading a compare view of a minified diff is very slow

Open kumar303 opened this issue 6 years ago • 10 comments
trafficstars

Describe the problem and steps to reproduce it:

Here's how I can reproduce it in my local environment:

  • sign in to dev
  • go to https://code.addons-dev.allizom.org/en-US/compare/502955/versions/1541798...1541798/?path=popup%2Fpopup.js

What happened?

It takes 20 seconds to load popup.js and Firefox shows the slow bar asking if I want to kill the web page

What did you expect to happen?

It should either load faster or say the diff is too big or something like that

Anything else we should know?

This was a problem with the old tool and, surprise, it's a problem with the new one!

The API request is http://localhost:3000/api/v4dev/reviewers/addon/502955/versions/1541798/compare_to/1541798/?file=popup/popup.json&lang=en-US

It responded in 844ms so it's not an API problem.

It's a JS / layout problem. Performance profile: https://perfht.ml/2TDrfVL

┆Issue is synchronized with this Jira Task

kumar303 avatar Mar 15 '19 15:03 kumar303

Oh, I see. That looks like a problem related to syntax highlighting and not with the diff. There are not a lot of changes in the API response. If you disable options.highlight in DiffView, it renders quit fast.

Given that it renders quite fast in the CodeView too, I believe the issue is related to the syntax HL in the DiffView component, likely because it tries to "apply" syntax HL on each token.

willdurand avatar Mar 15 '19 15:03 willdurand

Yep, syntax highlighting was going to be my guess. It wasn't obvious to me from looking at the perf profile. Hmm. I need to learn how to analyze those better.

kumar303 avatar Mar 15 '19 16:03 kumar303

The quickest fix here is probably to disable syntax highlighting when we detect minification (long lines or something) then offer a button to put highlighting back, maybe.

kumar303 avatar Mar 15 '19 16:03 kumar303

We could defer syntax HL in a web worker to avoid blocking the main thread: https://github.com/otakustay/react-diff-view/blob/6aa5399c52392e19f7f8fbe4af17b374b4339862/src/hocs/withTokenizeWorker.js

willdurand avatar Mar 15 '19 16:03 willdurand

I've noticed this issue reproducible for https://code.addons-dev.allizom.org/en-US/compare/390151/versions/1688198...1688302/ https://code.addons-dev.allizom.org/en-US/compare/495710/versions/1541610...1688333/ https://code.addons.allizom.org/en-US/compare/1002795/versions/2474840...2474841/

ioanarusiczki avatar Jul 02 '19 08:07 ioanarusiczki

Is #779 a dupe of this?

wagnerand avatar Jul 03 '19 16:07 wagnerand

Yes, maybe. There are a couple others that may be dupes but I was planning to check the STR and URLs for each to make sure we cover all cases.

kumar303 avatar Jul 03 '19 16:07 kumar303

We have a workaround in https://github.com/mozilla/addons-code-manager/issues/942 which should speed this up but, really, we can do syntax highlighting faster once https://github.com/mozilla/addons-code-manager/issues/928 lands so I'm going to keep this open as a way to test it.

kumar303 avatar Jul 12 '19 14:07 kumar303

@wagnerand This is actually fixed now, because we introduced code that disables highlighting for large files. It is being kept open in order to test/verify #928 when it lands.

  1. We should perhaps remove the mvp label from this, and bump it down the priority list as it's not currently reproducible.
  2. I wonder if we should bump #928 up the priority list. If we can fix it it might allow us to re-introduce syntax highlighting for large files, but perhaps that's not a particularly high priority item? We've already discussed the fact that there's not much point in highlighting minified files as they're virtually unreadable anyway, which is another reason that #928 might not be that high a priority. I just wanted to raise it to get your opinion.

bobsilverberg avatar Dec 11 '19 16:12 bobsilverberg

@bobsilverberg Sounds good, thanks! No need to bump #928 at the moment, but we might revisit that later.

wagnerand avatar Dec 11 '19 17:12 wagnerand