The source generation is completely non incremental due to rooting of compilation objects. There should not be *Syntax or symbol instances in the compilation pipeline, as they completely break the caching and increase memory usage. It's important to establish a value type data model of the things required for generating the source, see more here.
The source generation is completely non incremental due to rooting of compilation objects. There should not be
*Syntax
or symbol instances in the compilation pipeline, as they completely break the caching and increase memory usage. It's important to establish a value type data model of the things required for generating the source, see more here.https://github.com/Cysharp/ConsoleAppFramework/blob/48d550c2cc476b5773673b093c1678b46319dbdd/src/ConsoleAppFramework/ConsoleAppGenerator.cs#L39 and https://github.com/Cysharp/ConsoleAppFramework/blob/48d550c2cc476b5773673b093c1678b46319dbdd/src/ConsoleAppFramework/ConsoleAppGenerator.cs#L63-L66
Many libraries fall into this pit of failure. See similar issues in many other libraries that used
IIncrementalGenerator
in correctly:Related Roslyn issues:
Here's solid article from Andrew Lock about the issues: https://andrewlock.net/creating-a-source-generator-part-9-avoiding-performance-pitfalls-in-incremental-generators/
You can see here how one library fixed their incremental generator: https://github.com/k94ll13nn3/AutoConstructor/pull/83
It is also possible to add tests to test whether a pipeline is incremental: