Closed Bug 1778758 Opened 2 years ago Closed 2 years ago

Firefox using 100% of CPU on M1 Mac when large JavaScript sourcefile open in debugger

Categories

(DevTools :: Debugger, defect)

Firefox 103
defect

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1779173

People

(Reporter: brookerose1312, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:103.0) Gecko/20100101 Firefox/103.0

Steps to reproduce:

Open any website with a large JavaScript source file (or, even a moderately sized one, such as https://addons.mozilla.com/), and open the large source file (for example, addons.mozilla.com > static-frontend > amo-[numbers].js).

Actual results:

Firefox reaches 100% CPU usage and above on M1 Mac.

Expected results:

Firefox should not hang and reach large CPU usage.

https://share.firefox.dev/3atrL2o -- profiler permalink

Possible relevant CodeMirror bug ticket? https://github.com/codemirror/dev/issues/703

The Bugbug bot thinks this bug should belong to the 'DevTools::Debugger' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Debugger
Product: Firefox → DevTools

From what I can see, the relevant code is a function in CodeMirror that in the minified code is

function W(e, t, n, r, i) {
        null == t && -1 == (t = e.search(/[^\s\u00a0]/)) && (t = e.length);
        for (var o = r || 0, a = i || 0; ; ) {
          var l = e.indexOf("\t", o);
          if (l < 0 || l >= t) return a + (t - o);
          (a += l - o), (a += n - (a % n)), (o = l + 1);
        }
      }

Thanks for filing!

Nicolas, you mentioned a codemirror update, is there any bug filed for it? This performance issue might be a good motivation to do it?
And maybe we could also add a performance test here.

Flags: needinfo?(nchevobbe)

(In reply to Julian Descottes [:jdescottes] from comment #5)

Nicolas, you mentioned a codemirror update, is there any bug filed for it? This performance issue might be a good motivation to do it?

Yes, this is Bug 1773246 , and it could indeed be a good motivation. The debugger wouldn't be the easiest to migrate, but that would be a good exercise to know how to migrate the different features we have

Flags: needinfo?(nchevobbe)
See Also: → 1773246

I think the issue here is different from the one on GitHub. We seem to be spending most of our time in countColumn:

  function countColumn(string, end, tabSize, startIndex, startValue) {
    if (end == null) {
      end = string.search(/[^\s\u00a0]/);
      if (end == -1) { end = string.length; }
    }
    for (var i = startIndex || 0, n = startValue || 0;;) {
      var nextTab = string.indexOf("\t", i);
      if (nextTab < 0 || nextTab >= end)
        { return n + (end - i) }
      n += nextTab - i;
      n += tabSize - (n % tabSize);
      i = nextTab + 1;
    }
  }

Which takes a very long time to complete on the file from the STRs , which has 1.7 million columns.
This method still seems mostly intact in the newest code mirror implementations: https://github.com/codemirror/language/blob/main/src/stringstream.ts.

See Also: → 1779173
Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: