dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.9k stars 4.01k forks source link

IDE0072: Add missing cases to enum takes extremely long time for enums with many values. #65937

Open vsfeedback opened 1 year ago

vsfeedback commented 1 year ago

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work] In an application with a shared DLL across projects, an enum with many values (in my test case - 406 values - admittedly beyond the use of a typical enum), the switch expression IDE0072 refactor "add missing cases" takes extremely long - both attempts so far have gone >30 minutes before I killed the application.

Please consider a review of this feature - it's great, but the implementation smells a little bit like O(n^2) :)


Original Comments

Feedback Bot on 12/8/2022, 02:44 AM:

(private comment, text removed)

Sam Harwell [MSFT] on 12/8/2022, 01:38 PM:

(private comment, text removed)

Chris Danek on 12/9/2022, 05:40 PM:

(private comment, text removed)

Feedback Bot on 12/12/2022, 08:23 AM:

(private comment, text removed)


Original Solutions

(no solutions)

sharwell commented 1 year ago

@CyrusNajmabadi copying my comment from ADO to here:

The bulk of the work here is running the simplifier on all the switch expression cases. I believe the refactoring is generating fully-qualified references to the enum type, and then running the simplifier on them to reduce it to the simple enum name. I'm wondering if we could optimize this case by showing that if A.B.C.D simplified to C.D in a given context, then a later reference to A.B.C.E in the same context could simplify to C.E without running all the simplifier checks (specifically the speculative binding).