Repository navigation
Description
- Electron version: 1.8.x
- Operating system: All
This is a 2nd proposal related to #11303.
Add an "affinity" option for gathering several webpages in a single process.
Expected behavior
const w1 = new BrowserWindow({
width: 400,
height: 400,
webPreferences: {
affinity: 'myAffinity'
}
})
const w2 = new BrowserWindow({
width: 400,
height: 400,
webPreferences: {
affinity: 'myAffinity'
}
})
console.log(w1.webContents.getOSProcessId() === w2.webContents.getOSProcessId()) => trueChromium
We want to take advantage of the optional ability of Chromium to gather Web pages from the same site/domain in a single renderer process.
In a nutshell, you can have several pages hosted in the same renderer process (vs having a process per webpage).
Chromium process models
The mecanism can be fine-tuned and we can even decide which process will host which page (complying with the rule : a process can only manage webpages from the same site/domain).
It is promoted by OpenFin and intensively used by Thomson Reuters Eikon which embeds its own Chromium (CEF/C++)
Purpose is to save resources of the machine and prevent from reaching the limit of number of processes authorized by Chromium.
The challenge is to identify Web pages that can easily share the same process without being impacted too heavily by the performance of having a single process (have the same V8 engine, same thread, same messageLoop…) but this is another story.
Proposal
I would like to add an optional parameter affinity to the webPreferences of a BrowserWindow. This option identifies a renderer process (internally a Chromiun SiteInstance) candidat for hosting this page.
Class: BrowserWindow
Create and control browser windows.
Process: Main
BrowserWindowis an
EventEmitter.It creates a new
BrowserWindowwith native properties as set by theoptions.
new BrowserWindow([options])
optionsObject (optional)
...webPreferencesObject (optional) - Settings of web page's features.
...
affinityString (optional) - Sets the expected process hosting the page. Allow to gather
several pages in the same process. There are known limitations:
you can not host in the same site, pages with different preload file,
nodeIntegration or sandbox preferences.
Known limitations
Some options are managed at process level (provided through the commandline) :
- sandbox
- nodeIntegration
- preload
You can not mix in the same process, windows with such different options. The options of the process will be always applied.
Conclusion
I have already a MR ready to be submitted but I would like your feedback first.
The code changed is limited and does not impact usual workflow if the option is not set. I updated documentation and added unit tests.
Regards
Activity
groundwater commentedon Dec 20, 2017
Hi @emmkimme. Just to clarify, it sounds like you have a working fork you'd like to PR upstream, but would like to get some consensus on the idea first?
emmkimme commentedon Dec 21, 2017
Yes, absolutely, I worked on CEF/Chromium but not yet familiar with Atom/Electron. Just want to be sure my proposal makes sense. If you think it is better to raise directly a MR let me know.
MarshallOfSound commentedon Dec 21, 2017
I'd like to see a PR for this, I have concerns it will greatly increase the chance of crashes (sharing nodejs / v8 contexts across sites has historically been a Bad Thing). I'd definitely want the API tagged unstable / beta and depending on resulting binary change put behind a build flag.
But at least initially I'd like to see what it looks like and then perhaps get an idea of maintenance cost.
Sounds like a neat idea though that could save people a decent amount of resources if their sites benefit from it.
emmkimme commentedon Dec 21, 2017
Done : see #11501