CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

WinRT.SourceGenerator should implement IIncrementalGenerator instead of ISourceGenerator

Open sharwell opened this issue 1 year ago • 7 comments

Describe the bug

The RegisterForSyntaxNotifications API provided to ISourceGenerator produces an unavoidable, catastrophic performance penalty. Source generators operating on syntax need to be carefully rewritten implementing IIncrementalGenerator to avoid this overhead. https://github.com/microsoft/CsWinRT/blob/98122be4624e0b36b8bc2c48bcde6d9f39cd4e42/src/Authoring/WinRT.SourceGenerator/Generator.cs#L430

To Reproduce

Discovered during ETL and heap dump analysis of this issue: https://developercommunity.visualstudio.com/t/Poor-performance-on-intellicode-operatio/10717804

Expected behavior

Version Info

Additional context

sharwell avatar Aug 12 '24 14:08 sharwell

Absolutely needed, current situation in my solution. image

FrayxRulez avatar Aug 26 '24 14:08 FrayxRulez

@FrayxRulez I am curious, are you authoring a CsWinRT Component (WinRT component in C#) or just using the projection support and AOT support?

manodasanW avatar Aug 26 '24 22:08 manodasanW

@manodasanW I have a large WinUI app that consumes a few C++/WinRT projects, one of them definitely large too.

FrayxRulez avatar Aug 27 '24 05:08 FrayxRulez

I just implemented a WinRT.SourceGenerator implments IIncrementalGenerator for my own purpose. Since it's not fully tested so I decide not making a PR for it. If you are interested in this you can try it out.

Lightczx avatar Sep 03 '24 08:09 Lightczx

Unfortunately it looks like your generator is caching syntaxes and providers, which means it is not actually incremental.

dongle-the-gadget avatar Sep 03 '24 09:09 dongle-the-gadget

Unfortunately it looks like your generator is caching syntaxes and providers, which means it is not actually incremental.

Yes, technically not incremental, just reduced some generation attempts, it's enough for me though.

Lightczx avatar Sep 03 '24 09:09 Lightczx

Great! With version 2.1.3 released, it now takes me forever to rename a variable.🤓

Lightczx avatar Sep 12 '24 08:09 Lightczx