You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We currently have process reuse disabled in main.js, but considering how the native modules we use are now context-aware, we can start looking more into enabling process reuse.
There are other processes to look into, but for now, I would like to concentrate just on the extensionHost and watcherService. For those, I'm wondering
Are the processes killed + restarted during a reload?
Are the processes killed + restarted when a user opens a new folder or workspace? I'm currently trying to see if such actions are equivalent to a reload right now, but haven't yet found the code.
If yes to 1 and/or 2, can they be set up in a way using IPC such that the main process can send a reset signal during reloads? This way, we can continue using the same child process, and it's just the state of the child process that gets reset.
Raymond Zhao (@rzhao271) anytime a window either gets reloaded, closed or workspace changed within the window, the same code gets triggered to handle this because anyone in the window can participate on this event to either veto it from happening or doing some task (even long running). The events are ILifecycleService.onBeforeShutdown and ILifecycleService.onWillShutdown. The latter is triggered from here:
are there other child processes that the renderer spawns (e.g. search is also a process!)
are we sure all native modules are either context aware or no longer being used from the renderer (e.g.,only recently I found that the shared process -which is also a renderer process - was still not ready, see spdlog: Loading non-context-aware native module in renderer #120159)
are there any other implications for process renderer reuse that we need to be thinking about
Would you be interested in providing a PR for this work to help out on this task?
It looks like windows-process-tree is a dependency that we still drag into the shared process (here) which has not been adopted yet to be context aware iirc. A requirement would be to first make that module context aware unless we can control the process reuse per renderer.
are there other child processes that the renderer spawns (e.g. search is also a process!)
Deepak mentioned that I can look for places that call bootstrap-fork, and so I have the following list:
watcherService
customEndpointTelemetryService
ptyHostService
localProcessExtensionHost
searchService
The following places use loadURL to open a new window:
issueMainService
sharedProcess
window in windows/electron-main
are we sure all native modules are either context aware or no longer being used from the renderer (e.g.,only recently I found that the shared process -which is also a renderer process - was still not ready, see #120159)
Before doing any optimizations (this issue), we should double-check that all the native modules we use are context-aware. I'll create a separate issue for windows-process-tree.
are there any other implications for process renderer reuse that we need to be thinking about
Deepak provided two scenarios to consider, which are reloading a window, and switching the current workspace. Are there any other cases that could involve a process being reused?
If we implement a reset signal so that instead of killing + relaunching the window, the window state is simply reset, a part we would have to be careful about would be ensuring the old state doesn't leak into the new one.
Benjamin Pasero (@bpasero) in what situations does the shared process get reloaded ? Ignoring the case where we want to restart the process when it crashed.
Deepak mentioned that I can look for places that call bootstrap-fork
Yes, that is a good way to find out what child processes we spawn from a renderer.
The following places use loadURL to open a new window
Fyi that issueMainService has 2 different windows: the process explorer and the issue reporter
Before doing any optimizations (this issue), we should double-check that all the native modules we use are context-aware
Yes, I would suggest to do a pass over our dependencies of package.json including the optionalDependencies which list specific native modules for Windows only and find the ones which are still being used in renderers.
When I did that last time, I only found the windows-process-tree, while the others where only accessed from either a child process (like file watchers) or the main process.
Deepak provided two scenarios to consider, which are reloading a window, and switching the current workspace
At least for VSCode workbench windows, these 2 are the same. They both go through the same code and will trigger loadURL eventually.
If we implement a reset signal so that instead of killing + relaunching the window, the window state is simply reset, a part we would have to be careful about would be ensuring the old state doesn't leak into the new one.
I do not think that keeping the script context alive is an option currently, simply because we currently have no means of cleaning up all the state on shutdown. So far we get a free cleanup because the context changes everytime we call loadURL. My understanding is that we continue to call loadURL, even when process reuse is enabled, or not?
#35109 is related where we discussed the concept of doing a workspace change without a loadURL call, but there is lots of work involved currently.
So far we get a free cleanup because the context changes everytime we call loadURL. My understanding is that we continue to call loadURL, even when process reuse is enabled, or not?
That is correct and there will be a context change on reload. Based on the lifecycle hooks you have mentioned in #120431 (comment) , they are sufficient to have child processes restart in the process reuse model as well, we don't have to treat the process reuse mode as a different state.
#35109 is related where we discussed the concept of doing a workspace change without a loadURL call, but there is lots of work involved currently.
Benjamin Pasero (@bpasero) So this issue is essentially reviving #35109? I would also like to confirm what is meant by there being "lots of work involved currently", because I currently only see two blockers before we consider implementing some workspace reuse optimizations:
Verify the native modules are context-aware (shouldn't take too long)
Merging Electron 12 into Insiders and turning on process reuse (this one's riskier and we will likely have regressions to work on first)
Activity
rzhao271 commentedon Apr 2, 2021
CC Robo (@deepak1556)
bpasero commentedon Apr 3, 2021
Raymond Zhao (@rzhao271) anytime a window either gets reloaded, closed or workspace changed within the window, the same code gets triggered to handle this because anyone in the window can participate on this event to either veto it from happening or doing some task (even long running). The events are
ILifecycleService.onBeforeShutdownandILifecycleService.onWillShutdown. The latter is triggered from here:vscode/src/vs/workbench/services/lifecycle/electron-sandbox/lifecycleService.ts
Line 86 in 94c9ea4
I think we can easily use these events to kill processes when the
onWillShutdownis fired.The watcher is actually a IPC Client and it looks like the dispose method will kill the process.
I think the extension host already has code to participate in the shutdown so that extensions can properly get deactivated:
vscode/src/vs/workbench/services/extensions/electron-browser/localProcessExtensionHost.ts
Line 130 in 94c9ea4
A couple of things we have to make sure:
Would you be interested in providing a PR for this work to help out on this task?
bpasero commentedon Apr 3, 2021
It looks like
windows-process-treeis a dependency that we still drag into the shared process (here) which has not been adopted yet to be context aware iirc. A requirement would be to first make that module context aware unless we can control the process reuse per renderer.rzhao271 commentedon Apr 5, 2021
Deepak mentioned that I can look for places that call
bootstrap-fork, and so I have the following list:The following places use
loadURLto open a new window:windows/electron-mainBefore doing any optimizations (this issue), we should double-check that all the native modules we use are context-aware. I'll create a separate issue for
windows-process-tree.Deepak provided two scenarios to consider, which are reloading a window, and switching the current workspace. Are there any other cases that could involve a process being reused?
If we implement a reset signal so that instead of killing + relaunching the window, the window state is simply reset, a part we would have to be careful about would be ensuring the old state doesn't leak into the new one.
deepak1556 commentedon Apr 5, 2021
Benjamin Pasero (@bpasero) in what situations does the shared process get reloaded ? Ignoring the case where we want to restart the process when it crashed.
bpasero commentedon Apr 6, 2021
Yes, that is a good way to find out what child processes we spawn from a renderer.
Fyi that
issueMainServicehas 2 different windows: the process explorer and the issue reporterYes, I would suggest to do a pass over our
dependenciesofpackage.jsonincluding theoptionalDependencieswhich list specific native modules for Windows only and find the ones which are still being used in renderers.When I did that last time, I only found the
windows-process-tree, while the others where only accessed from either a child process (like file watchers) or the main process.At least for VSCode workbench windows, these 2 are the same. They both go through the same code and will trigger
loadURLeventually.I do not think that keeping the script context alive is an option currently, simply because we currently have no means of cleaning up all the state on shutdown. So far we get a free cleanup because the context changes everytime we call
loadURL. My understanding is that we continue to callloadURL, even when process reuse is enabled, or not?#35109 is related where we discussed the concept of doing a workspace change without a
loadURLcall, but there is lots of work involved currently.Robo (@deepak1556)
Never. We have no support to reconnect to the shared process currently.
deepak1556 commentedon Apr 6, 2021
That is correct and there will be a context change on reload. Based on the lifecycle hooks you have mentioned in #120431 (comment) , they are sufficient to have child processes restart in the process reuse model as well, we don't have to treat the process reuse mode as a different state.
rzhao271 commentedon Apr 6, 2021
Benjamin Pasero (@bpasero) So this issue is essentially reviving #35109? I would also like to confirm what is meant by there being "lots of work involved currently", because I currently only see two blockers before we consider implementing some workspace reuse optimizations:
38 remaining items
rzhao271 commentedon Mar 21, 2022
I'm wondering where the testplan item for this issue is, and/or whether we need a new one? Benjamin Pasero (@bpasero)
bpasero commentedon Mar 22, 2022
I think Robo (@deepak1556) covered that as part of the E16 and E17 test plan items previously.
deepak1556 commentedon Mar 22, 2022
Yup its covered in previous milestone testing #141268. This feature has already gotten plenty of coverage, does not require additional testing.