During the 2019.3 beta phase I reported that deleting assets inside Unity is significantly slower than deleting them via Windows Explorer.
Today I tested whether the same holds true with Unity 2020.2.0a21.
Results
Windows Explorer = 2 seconds
Unity 2020.2.0a21 = 6 seconds
Unity 2019.3.0a8 = 12 seconds (taken from this video )
Conclusion
Deleting assets performance improved significantly compared to Unity 2019.3. However, it continues to be significantly slower than deleting the files in Windows Explorer as well.
Thumbs up for the improvement compared against 2019.3, thumbs down for still being slower than Windows Explorer.
That’s kind of comparing apples to oranges - AssetDatabase.Refresh is the top level call for many different sorts of work Unity does to synchronize its internal asset database with your files. The actual work will differ depending on what’s changed (if no files have changed, the time taken by Refresh may be drastically different from if a file was added, which may take a different amount of time compared to if a file has been deleted).
Neither your windows explorer measurement nor your other test you linked includes the time taken by Unity to refresh its asset database after a file is deleted, whereas the measurement where you delete a file through Unity’s interface does.
The comparison numbers only tell a small part of the story and are kind of misleading without including the refresh time after deleting an asset through Explorer - having that number separate from the Explorer number (e.g. “2 seconds in Explorer, 3 seconds in Refresh” or whatever) makes sense though.
I get that deleting the asset in Unity has to take longer than in Explorer, as Unity also has info about the asset in the library that has to be cleaned out. If the performance is that much worse, it might be that the cleanup is happening one-by-one instead of all at once. Or something like that.
I just want to add some info about this case: we looked into it and we know why it’s slower.
We issue some commands to the OS once per file, such as copies and deletes. But on some OSs, there are functions to allow asking for multiple files to be deleted/copied all in one command. We don’t make use of this (but we should!)
This accounts for the huge time difference between doing the operation in Unity vs Windows Explorer.
It would be a bit of a rewrite to fix this in Unity, which is why it’s not been fixed yet, but hopefully it will be done at some point.
The AssetDatabase.Refresh stuff is also relevant, but it’s only a small factor compared to the issue of submitting the commands one file at a time.
Just upgraded a project to 2022.2.12 and deleting a single file now takes a ridiculously long time - I hadn’t noticed this until upgrading from the 21 LTS to 22.
So…things are not getting better on this front it doesn’t seem ;{
Deleting many trees (+1000), just makes unity hang forever. The fix is, to create a new Scene, copy all objects except the ones you want, then delete old scene… still in: 2023.3.
And also indeed, deleting an empty! folder, just freezes unity.