For a while I have been struggling with Visual Studio being painfully slow specifically on my DOTS project, and I believe that I have now narrowed down the cause to Entities.ForEach.
I have about 60 or so systems, almost all of them implemented using Entities.ForEach. To test, I deleted all of these systems and suddenly Visual Studio was performing great again. My guess would be it is related to the code generation it is doing?
I haven’t yet converted all of my systems to use plain old jobs to verify 100% that Entities.ForEach is the culprit, but from what I see now it seems likely that doing so will solve the issues I have been having. I have been wanting to move away from Entities.ForEach recently and this is a good reason to make me actually do it.
Not sure if there is anything that can be done about this, but I wanted to give my findings anyways.
My VS2022 V17.2.5 is also extremely slow. I assumed it was from moving to VS2022 when Unity 2021.3 & entities 0.50 required it. If it is the ForEach a fix would be nice, not in the mood for another workaround to work with DOTS :-).
I have the “Visual Studio Tools for Unity” installed with VS 2022.
I have “Visual Studio Code Editor” version 1.2.5 in the unity package manager.
I have “Visual Studio Editor” version 2.0.16 in the unity package manager.
Its slow for me at startup, it takes a minute to show the references and remove all the false build error. If slow startup was the only issue I could live with it. (The ServiceHub.RoslynCodeAnalysisService takes a lot of CPU during this time)
“Quick Actions and Refactorings” just stays are “loading suggestions”.
After fixing a build error the red line keeps showing for 10 seconds, at which point I am wondering if there is another error there. Its very annoying.
These things used to be near instant on VS2019 with Unity 2020.3 & entities 0.17.
I am using the latest VS package. There are many things that are slow, but here are some examples of things that bog me down a lot:
Quick Actions and Refactorings takes a long time to load
Saving is slow, often showing a “Executing code cleanup” dialog for several seconds or more
Document highlighting is slow to update, sometimes not updating at all until I save (and then see the previous point)
Refactoring names can take a long time to finish
Debugging is slow sometimes. I was testing debugging performance once and it took 15 seconds to continue from one breakpoint to the next when the breakpoints were on lines literally right next to each other. I’m not confident that this is actually related though.
I just recently refactored my code to split things up into multiple assembly definitions, and now every project is lightning fast except the project containing my ECS code.
I might have a look at Rider but on the whole I don’t have any issues with VS other than whatever is happening here.
Ha, you pretty much described my exact experience word-for-word.
Well it’s been very tedious, but after converting most of my systems I can confirm that VS is now running a lot better.
I still have 15 systems that use Entities.ForEach and the project is still very slightly sluggish compared to other projects, but nowhere near as bad as it was before.
So I guess unless there is actually something that can be fixed here, if you are experiencing this your options are to use Entities.ForEach less, or switch to Rider which according to the other posts here does not have this problem.
We have noticed this, and also noticed the impact on iteration time, so for 1.0 we’ve developed an alternative to EFE that requires several times less work from the sourcegenerators (which are both what slows down VS and also one of the many sources of bad iteration time in the unity editor). It unfortunately does require y’all (and also us) to convert manually, though.
I won’t go into what it looks like here because it’s kind of a long story and I’m not an expert on it; plus, it’ll be in the docs anyway.
For what it is worth, I’m still primarily using 0.50.1, 2020.3 LTS, and VS 2019 due to some custom tooling I haven’t bothered to try and migrate yet. One project uses Entities.ForEach extensively. Another doesn’t. Both have roughly the same iteration time for code changes and compilation. I think there is something else here at play that is causing slowdowns besides the codegen process itself.
Agreed. While I don’t use Visual Studios (and Rider has no issues with this) we have a few developers at work who do use Visual Studios (a mix of 2019 and 2022) and don’t have the reported issues in this thread.
The project has
625 Entities.ForEach
150 Job.WithCode
Which is far from a small count and I would expect to see crippling issues.
Maybe the same fix works for normal VS also? It’s just a pain that the .csproj files regenerate all the time so you have to perform the fix continually as you work.
It will very likely already get a lot better when you are migrating your legacy source generators to the recommended incremental generators. (I hope that this is already an ongoing effort)
Thank you! I think this also works for VS2022. After commenting out these lines its at an acceptable speed again. I did it in all the .csproj files of my project 247 hits in 40 files.