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
refactor: use v8 serialization for ipc #20214
Conversation
I did some preliminary performance testing. The numbers below are the average time taken, in milliseconds, to send a Uint8Array buffer of a given size, across 200 calls to With the existing mojo-based
With this PR, using v8's ValueSerializer:
So this seems to be a little less than twice as fast for this use case. |
Ref #18758 |
Could we possibly support both the existing serialization and the sca approach at the same time? I'm wondering if we can follow a deprecation path here or if this will have to be all or nothing. |
Tried this with some larger buffers: Before:
after:
|
@jkleinsc I'd like to first try to find a way we can make this at least more compatible with the existing structure, if not 1:1. If we can find a way that works for 99% of use cases, then I think we should cut over directly and accept the breakage. If we find fundamental issues that are not paper-over-able, then we should investigate ways we can expose this functionality differently (perhaps a new set of APIs like |
I also tried this with complex objects. The numbers below are for NxM objects, where N is the breadth and M is the depth. For example, a 2x3 object is:
A NaN represents a renderer crash. Before:
After:
So, quite a bit faster. I think the crashes are when constructing those stupidly large objects, rather than serializing them. And the new code does succeed on the 8x8 case, where the old code crashed. |
93ab58d
to
8301091
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool!
Comments / questions inline, but nothing fundamental. Overall this is really nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good
Release Notes Persisted
|
For anyone else interested, these changes have landed in nightly - https://github.com/electron/nightlies/releases/tag/v8.0.0-nightly.20191009 |
Will this be backported to 6.x? |
No, since it is a breaking change.
|
This PR is noted as a Breaking Changes for Electron 8.0.0 & 9.0.0 betas. Is there any difference in the IPC between versions 8 and 9? |
@slapbox I believe the plan in 8 is to use the new algorithm, but if it fails, emit a warning and fallback to the old algorithm. In Electron 9, they're going remove the fallback and warning and serializing bad data will start throwing exceptions. |
Is there any way to check if a variable is safe to be transferred through RPC calls? Could |
@Qrysto The most reliable way to check for serializability is to try sending the message, and catching the error. If for some odd reason you need to check in a way that's guaranteed not to send a message, you could try sending to a dummy channel that has no listeners, or if you're in the main process or an unsandboxed renderer, you can try the v8.serialize Node.JS API. |
Description of Change
BREAKING CHANGE
This changes IPC communication to use v8's Structured Clone algorithm instead of using the
base::Value
serialization defined innative_mate_converters/v8_value_converter.cc
. This is be faster, more featureful, and less surprising than the existing logic, since it more-or-less matches the logic that backspostMessage
.This brings about a 2x performance boost for large buffers and complex objects. Latency for small messages is not significantly affected.
User-observable differences from the existing IPC API:
NaN
,Infinity
, andundefined
are transferred as such, rather than being converted tonull
.Set
andMap
,Error
,RegExp
,Date
andBigInt
can be transmitted.Buffer
will be converted toUint8Array
.Float32Array
and friends) will be transmitted as they are, instead of being converted toBuffer
.null
s.Checklist
npm test
passesRelease Notes
Notes: IPC between main and renderer processes now uses the Structured Clone Algorithm.