perf: don't use JSON to send the result of ipcRenderer.sendSync.#8953
perf: don't use JSON to send the result of ipcRenderer.sendSync.#8953MarshallOfSound merged 7 commits intomasterfrom
ipcRenderer.sendSync.#8953Conversation
d822ebc to
9df0602
Compare
|
I'm wondering if this might be considered a breaking change since this changes the value returned to the renderer. event.returnValue = {
buffer: Buffer.from('test')
}Before this change the renderer would receive a plain old This is just one possible difference, there may be others, we should probably expand test coverage of the possible |
I could be wrong, but AFAICT this only changes the private API used by the scripts in |
@tarruda try the following on master vs. this branch: const {app, BrowserWindow, ipcMain} = require('electron')
const {Buffer} = require('buffer')
let window
app.once('ready', () => {
window = new BrowserWindow()
window.loadURL(`file://${__dirname}/index.html`)
})
ipcMain.on('test', (event) => {
event.returnValue = {
test: Buffer.from('test')
}
})<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
const {ipcRenderer} = require('electron')
Object.freeze(ipcRenderer.sendSync('test').test)
</script>
</head>
</html>On master, no error occurs, on this branch |
|
I've only saw this change from the POV of In any case, please consider these arguments in favor of merging:
|
I definitely agree this pull request improves things and should be merged eventually, I'm just worried about breaking existing apps. This is a public API and we are changing the format of the values it returns. Without proper test coverage of this API it is unclear what other behavior might be changing since |
|
👍 Maybe leave it for electron 2.0.0 then |
|
Closing this out for now, will revisit for Electron 2.0 since this is ultimately the right direction to go for this change. 👍 |
|
Reopening for consideration in the upcoming post-2.0 world |
|
@tarruda can you rebase this against master so that CI runs properly? Thanks! |
9df0602 to
fb3347e
Compare
fb3347e to
11b9d7e
Compare
zcbenz
left a comment
There was a problem hiding this comment.
Looks like a good thing to have.
|
Before this is merged I'd like to see some experimentation done to see what (if any) affect this will have on sendSync or the remote API's. It would be good if we good explicitly point to uses of the API and say "this will change" |
| mate::Dictionary global(args->isolate(), | ||
| args->isolate()->GetCurrentContext()->Global()); | ||
| v8::Local<v8::Value> sandboxed; | ||
| if (global.GetHidden("sandboxed", &sandboxed) && sandboxed->IsTrue()) { |
There was a problem hiding this comment.
Would it be better to use v8::Context::[Set/Get]EmbedderData for setting up this property per context rather accessing the global object ?
|
I think this would be a good candidate to land into @tarruda since we're looking at a 3.0 timeframe for this I don't think it's urgent, but could you address the comments above by @MarshallOfSound and @deepak1556? |
5869070 to
b0e132e
Compare
ipcRenderer.sendSync.ipcRenderer.sendSync.
|
There is one test failing on Windows x64, it seems like more of an issue with the test the same test is passing on Windows ia32 |
60e5e37 to
dc9e21a
Compare
|
@zcbenz can you please merge? |
|
We can have a quick discussion about this at summit, want to have a quick talk about impact |
|
@MarshallOfSound ok, what kind of impact are you concerned about? |
|
@MarshallOfSound this PR does not change how the types are presented to JS code using the remote module, that was done in #13055. This one should only be a performance optimization. |
|
@miniak I've got a couple of concerns
I just want someone to either document the side effects of this change (differences from JSON encoding) or tell me their are none (conclusively) |
|
- Change the return type of AtomViewHostMsg_Message_Sync from `base::string16`
to `base::ListValue`
- Adjust lib/browser/api/web-contents.js and /lib/renderer/api/ipc-renderer.js
to wrap/unwrap return values to/from array, instead of
serializing/deserializing JSON.
This change can greatly improve `ipcRenderer.sendSync` calls where the return
value contains Buffer instances, because those are converted to Array before
being serialized to JSON(which has no efficient way of representing byte
arrays).
A simple benchmark where remote.require('fs') was used to read a 16mb file got
at least 5x faster, not to mention it used a lot less memory. This difference
tends increases with larger buffers.
9656048 to
a7601bf
Compare
|
@codebytere do you maintain the release notes? How do we make sure the subtle change in behavior is documented? |
|
@MarshallOfSound can you unblock the PR? |
MarshallOfSound
left a comment
There was a problem hiding this comment.
Checked locally, this cleanly applies to the chromium 66 branch, approving and merging 👍
base::string16to
base::ListValueto wrap/unwrap return values to/from array, instead of
serializing/deserializing JSON.
This change can greatly improve
ipcRenderer.sendSynccalls where the returnvalue contains Buffer instances, because those are converted to Array before
being serialized to JSON(which has no efficient way of representing byte
arrays).
A simple benchmark where remote.require('fs') was used to read a 16mb file got
at least 5x faster, not to mention it used a lot less memory. This difference
tends increases with larger buffers.