Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The source generation is non-incremental #114

Closed
PaulusParssinen opened this issue Jun 4, 2024 · 1 comment · Fixed by #119
Closed

The source generation is non-incremental #114

PaulusParssinen opened this issue Jun 4, 2024 · 1 comment · Fixed by #119

Comments

@PaulusParssinen
Copy link

PaulusParssinen commented Jun 4, 2024

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.

}, (context, ct) => ((InvocationExpressionSyntax)context.Node, context.SemanticModel));

and
}, (context, ct) => (
(InvocationExpressionSyntax)context.Node,
((context.Node as InvocationExpressionSyntax)!.Expression as MemberAccessExpressionSyntax)!.Name.Identifier.Text,
context.SemanticModel))

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: k94ll13nn3/AutoConstructor#83

It is also possible to add tests to test whether a pipeline is incremental:

@neuecc
Copy link
Member

neuecc commented Jun 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants