C
C#3mo ago
Vlad

Using code generation to replace reflection, and Roslyn+Visual Studio performance.

Hey everyone, To better support trimming and AOT I'm shifting over some reflection code to code generation, which involves going over namespaces and types and generating functions to replace my usages of reflection. The generated code works and everything is fine, however it seems to me like Visual Studio's performance is way down and stuff like Ctrl+Click/F12 randomly stop working. Additionally hot reload randomly stops working and sometimes even watching values. I am observing this behavior across multiple computers and VS installations. According to the task manager Roslyn Code Analysis is taking a lot of CPU. My understanding is that it runs everytime I make a change (hence hot reloading breaking, maybe?) but I'm not sure how to deal with this, how to profile it and so forth. Are there any obvious gotchas I'm missing here?
7 Replies
sibber
sibber3mo ago
try #roslyn youre using incremental generators right?
Vlad
VladOP3mo ago
hm no I am using ISourceGenerator I guess I should be using incremental generators
sibber
sibber3mo ago
thats the old one dont use it
Vlad
VladOP3mo ago
got it, thanks
333fred
333fred3mo ago
$ig
MODiX
MODiX3mo ago
If you want to make an incremental source generator, please make sure to read through both the design document and the cookbook before starting.
333fred
333fred3mo ago
Using incremental generators, and especially using ForAttributeWithMetadataName, should significantly improve your experience
Want results from more Discord servers?
Add your server