Skip to content

shell.moveItemToTrash() locks the renderer process for large folders #71243

Closed

Description

Issue Type: Bug

This seems to have already been happening according to #56690 , but collaboration has been limited.

Steps to Reproduce:

  1. Generate a directory with a lot of files (i.e. 10GB)
  2. Try to delete it from VsCode

The window freezes and does not allow any action for a while. When it unfreezes, it hasn't really deleted the directory (although it shows as empty in the Explorer).

An easy way to generate such a directory is to build vcpkg ( https://github.com/Microsoft/vcpkg ) and install a large package, then try to delete the buildtrees, downloads, and installed directories.

VS Code version: Code 1.32.3 (a3db5be, 2019-03-14T23:43:35.476Z)
OS version: Windows_NT x64 10.0.17763

System Info
Item Value
CPUs Intel(R) Xeon(R) W-2133 CPU @ 3.60GHz (12 x 3600)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: enabled
surface_synchronization: enabled_on
video_decode: enabled
webgl: enabled
webgl2: enabled
Memory (System) 31.66GB (24.08GB free)
Process Argv
Screen Reader no
VM 0%

Activity

  1. added
    freeze-slow-crash-leak
    file-watcher
    on Mar 27, 2019
  2. MicahZoltu commented on Oct 10, 2019

    @MicahZoltu

    You don't even need a 10GB of files. I have almost never been able to delete node_modules from a project within VSCode without it hanging. The only time I can delete a node_modules folder from VSCode is if there are incredibly few dependencies (like 1-5 dependencies, including transitive).

  3. MicahZoltu commented on Oct 10, 2019

    @MicahZoltu

    To reproduce, clone just about any real-world Angular project, npm install, then try to delete node_modules.

  4. bpasero commented on Oct 17, 2019

    @bpasero
    Contributor

    Can you follow this wiki and post the results back here to understand more about why performance is so bad for you: https://github.com/Microsoft/vscode/wiki/Performance-Issues

    Thanks!

  5. added
    info-needed
    on Oct 17, 2019
  6. MicahZoltu commented on Oct 17, 2019

    @MicahZoltu

    image

    When you first click delete on the large package it spends some time at high CPU (one full core) and high disk IO. Eventually it will prompt you that you need administrator permission. Clicking that results in no meaningful CPU or Disk utilization, yet the entire VSCode UI is locked up. Can't interact with terminal, menus, etc. during this time. Eventually you'll be prompted with
    image, maybe a few of those depending on how big the folder is (I think it actually has to do with how many files, not actual folder size).

    If you keep clicking through the "Keep Waiting" you'll eventually get a UAC prompt. After clicking through the UAC prompt VSCode will go back to high CPU (low disk) but still locked up. You'll receive more "Keep Waiting" prompts during this time and eventually
    image

    After clicking delete permanently, disk utilization goes up (though not as high as initially) and the UI becomes responsive finally. If you continue to wait then eventually (no visual feedback) the folder will finish deleting.

    All of the above is with extensions disabled. All I did to reproduce on Windosw 10, VSCode 1.39.0 was:

    1. open VSCode 1.39.0 with extensions disabled
    2. open a folder in VSCode that has a package.json (can be empty)
    3. npm install augur-node (random project with a transitive dependency problem)
    4. right clicked on node_modules in the VSCode file explorer and choose delete

    At step 4 if you instead open Windows file explorer and right-click delete the folder it takes maybe 30 seconds (much faster than VSCode), but there are no lockups along the way and as long as I don't have VSCode open, the delete goes through without problems.

  7. bpasero commented on Oct 17, 2019

    @bpasero
    Contributor

    Micah Zoltu (@MicahZoltu) I just tried to reproduce but did not get the dialog. Though I can see a bit of freeze. How is the experience if you Shift+Delete so that you get the "Delete Permanently" directly and not getting asked to move to trash?

  8. MicahZoltu commented on Oct 18, 2019

    @MicahZoltu

    Shift+Delete appears to be instant (I didn't know you could shift-delete from within VS Code).

    I'm surprised that you are unable to reproduce this issue. I have had it happen to me on all of my (3) devices with VSCode installed, and it happens every time I try to delete a node_modules folder. It has also been a problem for as long as I can remember, and I have seen other people report the same symptoms.

    Are you running VSCode as admin perhaps? Not that I think it matters, but I am running VSCode from a per-user install, and I have Windows 10 default UAC settings.

  9. bpasero commented on Oct 18, 2019

    @bpasero
    Contributor

    Micah Zoltu (@MicahZoltu) so there is a technical difference between Delete and Shift-Delete:

    • Delete: moves the folder to the windows trash using a Electron API that will call some Windows API
    • Shift+Delete: we do the delete using node.js, bypassing the trash

    I feel this issue is Electron specific, not VSCode. Are you willing to conduct a small experiment trying to reproduce with Electron alone? This would involve you installing Electron Fiddle (https://electronjs.org/fiddle) and writing a bit of code that triggers the shell.moveItemToTrash API (https://github.com/electron/electron/blob/4-0-x/docs/api/shell.md#shellmoveitemtotrashfullpath) with the path of that large folder.

  10. MicahZoltu commented on Oct 18, 2019

    @MicahZoltu

    I just tested with Electron Fiddle. shell.moveItemToTrash('c:/path/to/node_modules') took about 13 seconds, but the Electron Fiddle UI did not lockup during that time.

    I just tested deletion again with VSCode. This time I didn't get the pop-ups for whatever reason, but the UI did still lock up completely for about 15 seconds.

    I would say that the problem here isn't how long it takes to delete the folder (that is an issue with Windows and moving large folders to the trash) but that the deletion occurs on the UI thread and is not an async function call, so if it takes a while to execute it will lock up the UI.

    There is an open issue to have Electron make that call async, though it doesn't appear it has much traction at the moment. It sounds like the recommendation currently is to execute that call in a worker thread, rather than in the renderer thread. I would think that moving this call to a worker thread wouldn't be too hard since all you need is a single callback on success, you don't need complex updates along the way. If this were wrapped up nicely it could be turned into an async function so the code that calls it just would need to add an await.

  11. MicahZoltu commented on Oct 18, 2019

    @MicahZoltu

    FWIW, a quick glance at VSCode suggests that this method is already being called from an async function, so someone merely needs to create an async wrapper around shell.moveItemToTrash and add an await. I would hope that doing such a thing is "easy" in Electron, but I have never used it so I don't know how it works or how worker threads work.

  12. bpasero commented on Oct 18, 2019

    @bpasero
    Contributor

    Micah Zoltu (@MicahZoltu) as far as I can tell, a web worker does not have access to this Electron API, so I see no real solution to this problem. I think Electron itself should move this call onto a separate thread (I think they could do that) and off the renderer. I am not even feeling comfortable calling this method from a different process (e.g. our main process) because it locks for 15s.

    The upstream issue is: electron/electron#11555

  13. 6 remaining items

  14. changed the title [-]VS Code misbehavior when deleting large directories[/-] [+]shell.moveItemToTrash() locks the renderer process for large folders[/+] on Oct 18, 2019
  15. added
    fixed-in-electron-18
    on Nov 17, 2020
  16. bpasero commented on May 3, 2021

    @bpasero
    Contributor
  17. added
    verification-needed
    on May 3, 2021
  18. bpasero commented on May 19, 2021

    @bpasero
    Contributor

    Can someone verify this that is seeing this using our insider builds? You can give our preview releases a try from: https://code.visualstudio.com/insiders/

  19. added
    bug
    and removed
    verification-needed
    on May 28, 2021
  20. added
    author-verification-requested
    on Jun 4, 2021
  21. locked and limited conversation to collaborators on Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

author-verification-requestedbugelectronfixed-in-electron-18freeze-slow-crash-leakupstreamupstream-issue-linkedverifiedwindowsworkbench-os-integration

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions