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

Fix support for typed arrays in remote/rpc-server #13055

Merged
merged 1 commit into from May 24, 2018

Conversation

Projects
None yet
3 participants
@miniak
Contributor

miniak commented May 24, 2018

Adds support for ArrayBuffer and all typed array views (except for DataView) in the remote module.

Also makes the IPC payload much smaller (in the net module tests the payload goes down from approx 13 KB to 5 KB) by using base64 encoding instead of an array of values.

for example when calling electron.remote.getCurrentWindow().getNativeWindowHandle(); this is the JSON with the return value

before:
[{"type":"buffer","value":{"type":"Buffer","data":[32,72,27,0,64,96,0,0]}}]
after:
[{"type":"buffer","value":{"type":"Buffer","data":"oAzG+9B/AAA="}}]

Also calling Buffer.from(value) instead of Buffer.from(value.buffer) would create an unnecessary copy of the data instead of just creating a different view of the underlying memory.

https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_buffer

Copies the passed buffer data onto a new Buffer instance.

https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length

This creates a view of the ArrayBuffer without copying the underlying memory. For example, when passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer will share the same allocated memory as the TypedArray.

@miniak miniak requested review from zcbenz and codebytere May 24, 2018

@miniak miniak requested a review from electron/reviewers as a code owner May 24, 2018

@zcbenz

This comment has been minimized.

Contributor

zcbenz commented May 24, 2018

There are tests failing related to this change.

@miniak

This comment has been minimized.

Contributor

miniak commented May 24, 2018

@zcbenz should be fixed now

@miniak

This comment has been minimized.

Contributor

miniak commented May 24, 2018

@zcbenz I still have issue with supports TypedArray in api-remote-spec.js. Actually it seems like Int16Array etc is not passed properly without my change, example:

var a = new Int16Array([256, 512, 768, 1024])
a -> Int16Array(4) [256, 512, 768, 1024]
Buffer.from(a) -> [0, 0, 0, 0]

so the test does not even seem to be correct. Just try changing const int16values = new Int16Array([1, 2, 3, 4]) to const int16values = new Int16Array([256, 512, 768, 1024])

you'll get this error

AssertionError [ERR_ASSERTION]: <Buffer 00 00 00 00> deepEqual Int16Array [ 256, 512, 768, 1024 ]
@miniak

This comment has been minimized.

Contributor

miniak commented May 24, 2018

@zcbenz I would suggest adding full support for all typed array types in a separate PR, I am willing to do that.

@zcbenz

This comment has been minimized.

Contributor

zcbenz commented May 24, 2018

@zcbenz I would suggest adding full support for all typed array types in a separate PR, I am willing to do that.

Sounds good to me 👍

@miniak miniak changed the title from Serialize buffer as base64 string in remote/rpc-server to Add proper support for typed arrays in remote/rpc-server May 24, 2018

@miniak

This comment has been minimized.

Contributor

miniak commented May 24, 2018

@zcbenz I've changed my mind, let's do it in this PR. It's quite simple

@miniak

This comment has been minimized.

Contributor

miniak commented May 24, 2018

@zcbenz I think I'm done with the changes. Can you please review?

@miniak miniak changed the title from Add proper support for typed arrays in remote/rpc-server to Fix support for typed arrays in remote/rpc-server May 24, 2018

@zcbenz

zcbenz approved these changes May 24, 2018

👍

@zcbenz zcbenz merged commit 4cfe5ec into master May 24, 2018

11 checks passed

WIP ready for review
Details
ci/circleci: electron-linux-arm Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-arm-test Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-arm64 Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-arm64-test Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-ia32 Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-x64 Your tests passed on CircleCI!
Details
ci/circleci: electron-mas-x64 Your tests passed on CircleCI!
Details
ci/circleci: electron-osx-x64 Your tests passed on CircleCI!
Details
continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details

@zcbenz zcbenz deleted the miniak/remote-buffer branch May 24, 2018

@poiru

This comment has been minimized.

Member

poiru commented May 24, 2018

See also #8953, cc @tarruda

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