Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Significant canvas performance degradation in v2.0.x #12042

Closed
MaxGraey opened this issue Feb 25, 2018 · 30 comments
Closed

Significant canvas performance degradation in v2.0.x #12042

MaxGraey opened this issue Feb 25, 2018 · 30 comments

Comments

@MaxGraey
Copy link
Contributor

MaxGraey commented Feb 25, 2018

  • Electron version: v2.0.0-beta.1
  • Operating system: Mac OSX: 10.13.3

Expected behavior

Performance similar to previous versions (especially v1.6.17)

Actual behavior

Slowdown approximately in 5-8x times

How to reproduce

  • Install electron v2.0.0-beta.1
  • Launch any canvas app like this for example:
<!DOCTYPE html>
<html>

  <head>
    <script src="https://cdn.rawgit.com/konvajs/konva/1.7.6/konva.min.js"></script>
    <meta charset="utf-8">
    <title>Konva Optimizing Strokes Demo</title>
    <style>
      body {
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color: #F0F0F0;
      }
    </style>
  </head>

  <body>
    <div id="container"></div>
    <script>
      var width = window.innerWidth;
      var height = window.innerHeight;

      var stage = new Konva.Stage({
        container: 'container',
        width: width,
        height: height
      });
      var layer = new Konva.Layer();
      stage.add(layer);

      var n = 100, shape;
      for (var i = 0; i < n; i++) {
        shape = new Konva.Circle({
          x: stage.width() * Math.random(),
          y: stage.height() * Math.random(),
          radius: 10 + 10 * Math.random(),
          fill: Konva.Util.getRandomColor(),
          stroke: 'black',
          shadowEnabled: false,
          draggable: true,
        });
        shape.strokeHitEnabled(false);
        shape.shadowForStrokeEnabled(false);

        layer.add(shape);
      }

      layer.draw();
    </script>

  </body>

</html>
  • drag some circle
@MaxGraey
Copy link
Contributor Author

It seems problem with new color correction stuffs which improve color banding in gradients.
Solution for Chrome v61: https://stackoverflow.com/a/46167982
For Chrome >= 62: https://stackoverflow.com/a/47165506

@bpasero
Copy link
Contributor

bpasero commented Feb 26, 2018

@Tyriar isn't this #11051 ?

@MarshallOfSound
Copy link
Member

@Tyriar If it is can you check those workarounds 😄 Might be worth documenting or something 🤔

@Tyriar
Copy link
Contributor

Tyriar commented Feb 26, 2018

Well #11051 was specifically on Linux, OP is on mac. Also I thought I verified this issue on v2 but I only checked on mac 😄

@alexeykuzmin
Copy link
Contributor

@MaxGraey

Expected behavior
Performance similar to previous versions (especially v1.6.17)

Is there any difference between 2.0.0-beta1 and the latest stable Electron 1.8.2?

@MaxGraey
Copy link
Contributor Author

MaxGraey commented Feb 27, 2018

Is there any difference between 2.0.0-beta1 and the latest stable Electron 1.8.2?

Yes, as well. But difference between 2.0.0-beta1 and 1.6.x/1.7.x is much wider. I just mentioned that canvas perf for 1.6.17 the best on OSX in my opinion.

By the way. Is it make sense include degradation tests into electron test set for clarify how migration influence from version to version on different platforms? Because it seems this degradation has a long story

@MaxGraey
Copy link
Contributor Author

MaxGraey commented Feb 27, 2018

For 1.6.x/1.7.x:

getGPUFeatureStatus {
  '2d_canvas': 'enabled',
  flash_3d: 'enabled',
  flash_stage3d: 'enabled',
  flash_stage3d_baseline: 'enabled',
  gpu_compositing: 'enabled',
  multiple_raster_threads: 'enabled_on',
  native_gpu_memory_buffers: 'enabled',
  rasterization: 'enabled',
  video_decode: 'enabled',
  video_encode: 'enabled',
  vpx_decode: 'enabled',
  webgl: 'enabled',
  webgl2: 'enabled'
}

for >= 1.8.x

getGPUFeatureStatus {
  '2d_canvas': 'unavailable_software', // <-- turned to software mode
  flash_3d: 'enabled',
  flash_stage3d: 'enabled',
  flash_stage3d_baseline: 'enabled',
  gpu_compositing: 'enabled',
  multiple_raster_threads: 'enabled_on',
  native_gpu_memory_buffers: 'enabled', // <-- this disable on 2.0.0-beta1 as well
  rasterization: 'unavailable_software',  // <-- turned to software mode
  video_decode: 'enabled',
  video_encode: 'enabled',
  webgl: 'enabled',
  webgl2: 'enabled'
}

So we need
turn on ignore-gpu-blacklist or enable enable-accelerated-2d-canvas, enable-gpu-rasterization and enable-native-gpu-memory-buffers

But with this hints performance lower than 1.6.x/1.7.x anyway.

@alexeykuzmin
Copy link
Contributor

JFYI gpu_rasterization has been disabled on Mac >= 10.13 as a workaround for "Rendering glitches in High Sierra (macOS 10.13)".

@MaxGraey
Copy link
Contributor Author

MaxGraey commented Feb 27, 2018

I haven't this issue in Electron 1.7.9 with and without this hints, but I reset NVRAM more recently. Anyway in my current browser (Chrome 63) all acceleration is enabled by factory default and works perfectly.

@npezza93
Copy link

npezza93 commented Mar 8, 2018

I was able to reproduce this on macOS. It is considerably slower than 1.8.3 on 2.0.0-beta.2

@Tyriar
Copy link
Contributor

Tyriar commented Mar 8, 2018

@npezza93 oh? I guess I'll have to try again, the main thing I checked for was 60ish fps in the terminal. Can you give some approximations of the numbers you were seeing?

@npezza93
Copy link

npezza93 commented Mar 8, 2018

On 1.8.x
screen shot 2018-03-08 at 8 09 44 am

On 2.0 beta
screen shot 2018-03-08 at 7 35 55 am

Both of the big blocks I ran the same command in xterm (I cat'd a yarn.lock file). In 1.8 it took about 2.5 seconds in 2.0 it took over double that.

@npezza93
Copy link

npezza93 commented Mar 8, 2018

Hey @Tyriar, some more numbers and some steps to repro:

Using the example electron app inside node-pty(https://github.com/Tyriar/node-pty/tree/master/examples/electron), I ran cat node_modules/xterm/package-lock.json from inside the example app. I used electron versions 1.7.11 and 2.0.0-beta.2 and saw the following results.

v1.7.11
screen shot 2018-03-08 at 5 45 19 pm

v2
screen shot 2018-03-08 at 5 38 35 pm

@MaxGraey MaxGraey changed the title Significant canvas performance degradation in v2.0.0-beta.1 Significant canvas performance degradation in v2.0.x Mar 9, 2018
@ckerr
Copy link
Member

ckerr commented Mar 12, 2018

This can't be fixed until c63. There are switches that apps can use to speed things up; however some may have side-effects and so they can't be done unilaterally in every case.

@MarshallOfSound has been volunteered 🍺 to write up documentation for these options for the 2.0.0 release

@MarshallOfSound
Copy link
Member

@npezza93 Can you try your repro running electron with --ignore-gpu-blacklist

@npezza93
Copy link

Without flag:
screen shot 2018-03-12 at 5 07 56 pm
With flag:
screen shot 2018-03-12 at 5 09 22 pm

Worked like a champ! Thanks, @MarshallOfSound!

@MarshallOfSound
Copy link
Member

@npezza93 Good to hear we identified the issue, but our main point still stands. This won't be properly fixed for a while. By using this flag you are telling Chromium to ignore the GPU blacklist it uses to determine feature stability on certain OS's / GPU's. The thing that will affect you the most is graphical artifacts appears / graphical glitches on macOS high sierra and nvidia GPU's. If it's 100% required use the flag, but if you can avoid it and take the performance hit until Apple fix the nvidia drivers on high sierra I'd recommend doing that 👍

@ckerr ckerr added the blocked/upstream ❌ Blocked on upstream; e.g. Chromium or Node label Mar 13, 2018
@ckerr
Copy link
Member

ckerr commented Mar 13, 2018

Marking this as blocked-on-upstream for now, as there's not a lot that can be done in Electron until this is fixed upstream.

@bpasero
Copy link
Contributor

bpasero commented Mar 13, 2018

@MarshallOfSound @ckerr is this the same consequence as applying #10898 for 1.7.x? VS Code was already running with that patch for a while now and I would like to understand if the performance regression originates from there or if this is something new.

@Tyriar
Copy link
Contributor

Tyriar commented Mar 13, 2018

@bpasero I do not see a particular change in performance between our 1.7 and 2.0 VS Code builds, that may be because we've tweaked flags already though?

@MarshallOfSound
Copy link
Member

@bpasero Afaik the performance regression stems from that patch (or it's counterpart in chromium)

@Tyriar It is also hardware specific, depends on the GPU in your mac 👍

@Tyriar
Copy link
Contributor

Tyriar commented Mar 14, 2018

@MarshallOfSound this sounds a lot like #10923, did that patch get reverting while upleveling Chromium?

@bpasero
Copy link
Contributor

bpasero commented Mar 15, 2018

It looks like this patch still exists in Electron 2.0.x (proof: https://github.com/electron/libchromiumcontent/blob/electron-2-0-x/patches/043-fix_rendering_glitches_on_high_sierra.patch) because the related Chrome issue was fixed after Chrome 61 (possibly Chrome 62?).

VSCode always had this patch, we backported it early on to 1.7.x.

@Tyriar
Copy link
Contributor

Tyriar commented Mar 21, 2018

I actually am seeing this on Linux. Here's the output of getGPUFeatureStatus:

{ '2d_canvas': 'unavailable_software',
  checker_imaging: 'disabled_off',
  flash_3d: 'unavailable_software',
  flash_stage3d: 'unavailable_software',
  flash_stage3d_baseline: 'unavailable_software',
  gpu_compositing: 'unavailable_software',
  multiple_raster_threads: 'enabled_on',
  native_gpu_memory_buffers: 'disabled_software',
  rasterization: 'unavailable_software',
  video_decode: 'unavailable_software',
  video_encode: 'unavailable_software',
  webgl: 'enabled_readback',
  webgl2: 'unavailable_off' }

Running with command line flags fixes the issue:

./scripts/code-cli.sh --enable-accelerated-2d-canvas --enable-gpu-rasterization --ignore-gpu-blacklist --enable-native-gpu-memory-buffers

v1.7 has all the correct flags set.

@ckerr
Copy link
Member

ckerr commented Mar 26, 2018

Now that electron/libchromiumcontent#489 has landed, this may be ameliorated in 2.0.0-beta.6 which will be out in a day or two

@Tyriar
Copy link
Contributor

Tyriar commented May 15, 2018

FYI I think electron should revert electron/libchromiumcontent#489 as removing this version of macOS from the blacklist reintroduces the square artifacts microsoft/vscode#48043

VS Code is solving the problem by adding a DOM fallback to the canvas implementations. There will always be environments that have been blacklisted by Chromium for various reasons (like my work Linux desktop), so we needed a general solution.

@bpasero
Copy link
Contributor

bpasero commented May 15, 2018

I think we cannot ship with a 2.0 that brings back the ugly square artefacts. So I am +1 for reverting the GPU blacklist change if that causes it.

@bpasero
Copy link
Contributor

bpasero commented Jun 7, 2018

@Tyriar @deepak1556 it looks like Chrome is stating that the rendering issues have been fixed in macOS 10.13.4 and so their latest patch is actually going even further by blacklisting only if macOS < 10.13.4 (via commit).

@bpasero
Copy link
Contributor

bpasero commented Jun 10, 2018

Unfortunately at least one user confirmed that the background artefacts are still happening even with latest macOS 10.13.5 for him.

@MaxGraey
Copy link
Contributor Author

I should mentioned this problem resolved in v3.0.0-beta.1 with Chromium 66 for MacOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants