Closed Bug 1819269 Opened 1 year ago Closed 1 year ago

disableEmptyLines could be faster

Categories

(DevTools :: Debugger, task)

task

Tracking

(firefox112 fixed)

RESOLVED FIXED
112 Branch
Tracking Status
firefox112 --- fixed

People

(Reporter: nchevobbe, Assigned: nchevobbe)

Details

Attachments

(1 file)

The function was showing up in a profile (not in big ways, but looks like it could be improved)

https://searchfox.org/mozilla-central/rev/aa3ccd258b64abfd4c5ce56c1f512bc7f65b844c/devtools/client/debugger/src/components/Editor/EmptyLines.js#53-74

disableEmptyLines() {
  const { breakableLines, selectedSource, editor } = this.props;

  editor.codeMirror.operation(() => {
    editor.codeMirror.eachLine(lineHandle => {
      const line = fromEditorLine(
        selectedSource.id,
        editor.codeMirror.getLineNumber(lineHandle)
      );

      if (breakableLines.has(line)) {
        editor.codeMirror.removeLineClass(
          lineHandle,
          "wrapClass",
          "empty-line"
        );
      } else {
        editor.codeMirror.addLineClass(lineHandle, "wrapClass", "empty-line");
      }
    });
  });
}

2 immediate things are visible:

  1. fromEditorLine is checking if the source is wasm. And so here we check it for every line, while this information is unique per file

https://searchfox.org/mozilla-central/rev/aa3ccd258b64abfd4c5ce56c1f512bc7f65b844c/devtools/client/debugger/src/utils/editor/index.js#73-79

export function fromEditorLine(sourceId, line) {
  if (isWasm(sourceId)) {
    return lineToWasmOffset(sourceId, line) || 0;
  }

  return line + 1;
}
  1. Using codeMirror.eachLine means that we need to call codeMirror.getLineNumber, for each line. Since codeMirror.(add|remove)LineClass can take a line index instead of a lineHandle, we could have a simple for loop instead.
  • Replace codeMirror.eachLine with a simple for loop
  • Change fromEditorLine signature so it takes a new parameter indicating
    if the source is wasm. This allows us to only compute this information once
    per file, and not for each line of a file.

Depends on D171186

Pushed by nchevobbe@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/52980b1f16ff
[devtools] Make disableEmptyLines faster. r=jdescottes
Pushed by nchevobbe@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/7edfdbd5daf0
[devtools] Make disableEmptyLines faster. r=jdescottes
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 112 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: