electron: gRPC roundtrips on Windows are significantly slower in renderer processes than in the main process

  • Electron Version: 2.0.7, 3.0.0-beta.4
  • Operating System (Platform and Version): Windows 10. Windows Server 2016.
  • Last known working Electron version: -

Expected Behavior I am using the grpc native node module in an Electron app. I expect similar roundtrip performance when sending gRPC messages in the main process vs. in the renderer process.

Actual behavior On macOS, performance is equivalent. On Windows, the roundtrip times for gRPC messages sent from the renderer process are, on average, ~200x slower than when sent from the main process.

To Reproduce

This repo shows the described behavior: https://github.com/descriptinc/grpc-electron-test/tree/sr/electron-2.0

$ git clone -b sr/electron-2.0 https://github.com/descriptinc/grpc-electron-test
$ cd grpc-electron-test
$ yarn install

# in one terminal
$ node example/greeter_server.js

# in another terminal
$ yarn start

It runs the same gRPC test in the main process and in the renderer process and then shows the results in the renderer BrowserWindow. It computes the average round-trip time for a simple gRPC message (200 messages, sent at an interval of 10 ms. The problem persists even if the interval is much greater).

On Windows I get a result like:

Average gRPC roundtrip (running in main): 0.62ms
Average gRPC roundtrip (running in renderer): 145.94ms

While on macOS I get a result like:

Average roundtrip (running in main): 1.29ms
Average roundtrip (running in renderer): 1.33ms

Screenshots Windows: image

macOS: image

I get the expected behavior in Windows if I switch to the alpha/experimental @grpc/grpc-js module. See: https://github.com/descriptinc/grpc-electron-test/tree/sr/electron-3.0-grpc-js (Electron 3 is required because @grpc/grpc-js requires node >= 9.0.0).

image

Additional Information I’m not sure if the real issue here is in Electron or in gRPC. I opened an issue there, too: https://github.com/grpc/grpc-node/issues/489

I’m guessing that this is somehow related to the different way that Windows and Mac/Linux implement the node.js runtime binding in the renderer process, i.e.,

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

The issue is still reproducible on the latest Electron versions:

OS Electron Main Time (ms) Renderer Time (ms) Source Code
Win 10 12 0.3 497.56 electron-12

However, this issue doesn’t really matter anymore: grpc has been deprecated in favor of @grpc/grpc-js, which doesn’t have this issue.

One thing about the grpc native module is that it interacts with the libuv event loop directly, and possibly in an unusual way. The libuv event loop is implemented differently on different platforms and that may also be true of the Chrome event loop.

How Electron integrates Chromiums and Node’s event loop varies between renderer and main as well, if the module is doing libuv trickery I’m not suprised it’s getting mixed results when we are also doing some libuv trickery 😄