Cysharp / ConsoleAppFramework

Zero Dependency, Zero Overhead, Zero Reflection, Zero Allocation, AOT Safe CLI Framework powered by C# Source Generator.
MIT License
1.54k stars 88 forks source link

The source generation is non-incremental #114

Closed PaulusParssinen closed 1 month ago

PaulusParssinen commented 1 month ago

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:

neuecc commented 1 month ago

Thank you for the wealth of useful information! I will attempt to make corrections based on the information you have provided!