Skip to content

Acquiring compilations when source generators are involved can significantly impact language features (i.e. completion) #55578

@NTaylorMullen

Description

@NTaylorMullen

Background & Problem

When investigating a customer reported issue of C# completion behaving slowly I started to peel the onion as to what was going on. Turns out source generators were taking up a significant portion of time which in-turn block language features like completion:

OpO1Re3Txu

After profiling the issue and digging through Roslyn's source generator runners I found that source generator calculations were consuming nearly 93% of the time for completion:
image

Digging into some specific generators I also found that Razor's incremental source generator was also taking up roughly 53% of the time:
image

Solution

Given source generators are a public extension point now and many of them will be written in days to come we need to ensure our language features continue to work even in the presence of slower generators. @sharwell had some ideas about the language feature performance interaction in this area and proposed:

  1. We'd have a "frozen partial compilation" which would have partial frozen semantics avoid source generator execution. It'd assume the last known SG output is still the correct one to prevent us from re-running the SG aggressively. Consider the case of an analyzer that takes 20 seconds to run: for the first 20 seconds, APIs defined by source generators would not appear in high-profile features like completion. After that we'd update models for generators every 20s (assuming they can run fast enough).

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions