-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Remove dependency on node require for startup code path #98682
Comments
Another topic that is directly related to the startup path is code caching. Currently we rely on https://nodejs.org/api/vm.html#vm_script_createcacheddata to create the cache data and use for scripts required via node. In the sandbox case, we will have to rely on the code caching from blink. The cache data created in both cases rely on the same v8 api except in blink case certain heuristics are applied. I would highly recommend to watch https://www.youtube.com/watch?v=YqHOUy2rYZ8 which explains the state of code caching in chromium before reading the solution below. Tl:dr;
Given this, there is still some area of control we can gain when creating code cache with blink. For desktop apps it doesn't make sense to do the cold, warm and hot run checks, also the validity period of the script. This was exactly the case for PWA's and chromium added a new flag that would bypass these heat checks but the catch is that the scripts had to be served from service worker https://bugs.chromium.org/p/chromium/issues/detail?id=768705. After looking around a bit there is already a command line switch --v8-cache-options, with a little patch to chromium we can propagate a new flag We can take a chrome trace once the pieces are in place and compare how much is the saving with/without the heat checks. The crust of the code caching heuristics are here if needed. Also one more info, scripts from dedicated worker, shared worker have hardcoded cache type which currently defaults to the heuristic based caching. I am not addressing this, since I don't think there is much gain here. |
I can take care of this. By now we can use the performance-api (https://developer.mozilla.org/en-US/docs/Web/API/Performance) which also has a counter part in node.js |
Adding @bpasero fro the |
I have removed the |
@deepak1556 @alexdima this needs a bit of guidance to understand what should happen. Given the number of dependencies to node.js, I wonder if it would be better to introduce a new So I guess the bottom line is: how can we move forward on dropping the |
I need a hint what the path should be, e.g. naively putting this in to <script src="../../../../bootstrap.js"></script>
<script src="../../../../bootstrap-window.js"></script>
<script src="workbench.js"></script> Does this require loader configuration similar to web? vscode/src/vs/code/browser/workbench/workbench.html Lines 29 to 43 in 453454b
|
Sorry for not being clear, answers inline
The problem we are trying to solve in this issue is to eliminate the node requires with relative paths, as these are not working properly with custom protocols for unknown reason
The problematic ones are only
The node.js dependencies inside the bootstrap script can be present the way they are as long as they are not hardcoded relative paths, the loading of these modules will not be affected by the custom protocol transition. Based on my search in the codebase, we only had
No we don't need it for fixing only the bootstrap paths, since the workbench.js on desktop expects the boostrap code to be available, it would be sufficient to have something like
or
I try to resolve the resources in the protocol handler wrt the app resources path 86b7bbc , so the above should work just fine.
Yes this should be done along side sandbox workbench, which will have the loader config similar to web. I think this is the end goal, but as you noted its not something we can push to users currently. |
I have merged my changes which:
I think the next steps are to fix the remaining vscode/src/bootstrap-window.js Line 87 in a3f86f0
As discussed, the loader probably needs changes to be loaded through
|
With the latest changes I pushed and the unblock of the |
Very cool, given we are approaching endgame soon, I wonder if the switch to custom protocol should happen in debt week to give us a bit more insiders coverage. |
Yup @bpasero that would be the way to go, there is still some polishing left and also we are currently iterating E8 perf numbers, it is ideal to switch this in debt week. |
With: https://domoreexp.visualstudio.com/Teamspace/_git/electron-build/pullrequest/321429 Code caching now works with custom protocols, look for the Here are some additional observations,
There is still a 300ms difference between loading via node.js and chromium. The difference is mainly attributed to the network layer that loads the files rather than the v8 compilation stage which now uses the cache. For ex: In a typical script loading flow that starts from Will compare the product build numbers once they are out. Side Note: With Chrome >75 there is a feature called script streaming which allows v8 to parse the scripts from network on a background thread instead of having to wait on the main thread https://v8.dev/blog/v8-release-75#script-streaming-directly-from-network, this doesn't work for custom protocols but have fixed that in the above PR, so we now have script streaming too. There is catch until chrome > 91 or atleast till https://chromium-review.googlesource.com/c/chromium/src/+/2725097 lands , script steaming only works for scripts larger than 30kb. So to try this feature in OSS build, start the app with |
👏 |
I'm happy to help our here where I can. I'd recommend turning on SmallScriptStreaming along with V8OffThreadFinalization, otherwise the overheads tend to outweigh the benefits of streaming small scripts. This should be fine to do on electron built on top of chromium M88 or above. |
@LeszekSwirski thanks for the pointer on the I see the |
The In general though, I wouldn't expect streaming to help unless you're loading multiple scripts in parallel, or able to execute scripts in parallel with loading; otherwise, you're just moving the same operations from one thread to another, but your end-to-end latency stays the same. In the linked trace, it looks like there's not much being loaded alongside workbench.js, and it looks like actually parsing workbench.js is pretty short, so improvements may be modest. |
9636518 enables Code cache folder is partitioned per commit here: vscode/src/vs/code/electron-main/app.ts Line 164 in 2cb7b42
We store the code cache into the same folder as we do for our node.js based cache to benefit from reusing our clean up task ( I had to find an alternative solution for figuring out if cached data is used or not because we currently have no API for that. My strategy is to assume cached data is present whenever VSCode is running for the Nth+1 time for a commit: vscode/src/vs/workbench/services/timer/electron-sandbox/timerService.ts Lines 103 to 113 in 745e354
//cc @jrieken @deepak1556 |
Moving to July for enabling this permanently. For June we aim to ship this with a flag to disable it in case needed. |
Refs #92164
Things to do:
VSCODE_NODE_CACHED_DATA_DIR
)While rewriting our asset resolution over file protocol to use a custom protocol https://github.com/microsoft/vscode/tree/robo/vscode-file , I hit this weird error where relative requires failed.
I couldn't repro the issue with electron, so not sure whats happening here. As the error is not from the loader but rather failure from node require.
Instead of trying to tackle this, @alexdima suggested more robust approach that will align well with the sandbox renderer. We start removing the direct usage of node require on a case by case basis. Right now the low hanging fruit is the bootstrap, loader code and perf module. I am creating this task to tackle these.
performance module in workbench @jrieken
bootstrap-window require, which can be inlined as a
<script>
@bpaserovscode-loader @alexdima
<script>
tagsfile
scheme in https://github.com/microsoft/vscode-loader/tree/master/src/core<script>
with relative paths and let chromium/blink resource loader resolve it. That way we can make it independent of the page's protocol.These changes will let the app specific resources (scripts, images, css etc) to be handled by the protocol handler and also let chromium use respective caching mechanisms at the loader level.
The text was updated successfully, but these errors were encountered: