Looking for a better way to trace source generator and code refactoring performance #71429
-
Hi, I am working on an incremental source generator (unfortunately I cannot share the code right now). When using it in a large project in Visual Studio, code refactorings become slow (for example, selecting a block of code and pressing I managed to improve it significantly (~4x), by using the performance profiler to figure out what is being executed and improving my caching accordingly, but I have reached a point where I don't know how to proceed. In my current version, the delay is 7-9 seconds. ~2% of the CPU usage is inside my source generator, while ~75% of the CPU usage occurs inside the built-in method This behavior does not appear to exist with other source generators (unsure, not tested many), so it is probably an issue with mine, but I have no way of knowing what the issue is. Using GeneratorTracer I can see that my generator is being called ~30 times during the operation, with each call taking 75 ms on average. That adds up to ~2.5 seconds, which only accounts for a third of the delay time. Unfortunately, GeneratorTracer does not give me an indication of which steps of the pipeline are being executed or in what order. My pipeline has Q: Is there a better method for tracing a source generator's pipeline when running inside Visual Studio (since the behavior I am trying to trace is specific to VS)? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This was addressed in #70466 and #70477.
Woof. That's a reallllly slow generator. For context, an IDE feature needs to run in a few ms tops (with 50 being the high water mark where we consider things to be seriously problematic). Having a generator itself take 75ms effectively means that every semantic feature is now over budget. For context, getting the compilation after an edit (without SGs) should take microseconds. We're adding docs here: #71059 to help explain how to write a good incremental generator.
It's going to be hard to help out then. However, here's a few good rules of thumb:
You can then test generator performance by writing a simple console app that does the following:
Run this under a profiler and you'll see the cost of just the generator. We can also help out in discord https://discord.com/channels/143867839282020352/598678594750775301. Though, without the source, it will be hard to tell. Most likely something is going wrong in steps 1-3 above. |
Beta Was this translation helpful? Give feedback.
This was addressed in #70466 and #70477.
Woof. That's a reallllly slow generator. For context, an IDE feature needs to run in a few ms tops (with 50 being the high water mark where we consider things to be seriously problematic). Having a generator itself take 75ms effectively means that every semantic feature is now over budget.
For context, getting the compilation after an edit (without SGs) should take microseconds.
We're adding docs here: #71059 to help explain how to write a good incremental generator.