-
Couldn't load subscription status.
- Fork 4.2k
Try to reuse initialized generator drivers when we can #80845
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
base: main
Are you sure you want to change the base?
Try to reuse initialized generator drivers when we can #80845
Conversation
| // HACK: we probably shouldn't have this be a static instance, but this is easier than threading it through from the Workspace layer. | ||
| internal static readonly GeneratorDriverCreationCache Instance = new(); | ||
|
|
||
| private ImmutableDictionary<ProjectId, TaskCompletionSource<GeneratorDriver>> _driverCache = ImmutableDictionary<ProjectId, TaskCompletionSource<GeneratorDriver>>.Empty; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't looked at the whole pr, but we rarely cache TCS. We cache AsyncLazy instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can probably move this on; this changed a bit as I wrote it and since it's draft I didn't give a re-think.
| // There is already some other work in process to create a driver for this project; we'll want to await that work and then | ||
| try | ||
| { | ||
| // TODO: we don't have a WithCancellation() that could be used here, so we should use some alternate pattern to get the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think AsyncLazy would handle that
| { | ||
| data.onAfterUpdate?.Invoke(oldSolution, newSolution); | ||
|
|
||
| newSolution.CompilationState.ClearGeneratorDriverCaches(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc
...es/Core/Portable/Workspace/Solution/SolutionCompilationState.GeneratorDriverCreationCache.cs
Outdated
Show resolved
Hide resolved
We're seeing a performnace issue in Razor projects in cohosting scenarios. The first run of the Razor generator is relatively slow, and so ideally we wouldn't have that happen more than once. However, since multiple features might request compilations for a Razor project during startup in parallel, it's possible that all of those parallel invocations might initialize the generator multiple times if they happen to be different Solution instances. This change tries to ensure that when we're creating a GeneratorDriver for a project when we don't already have one, we'll do that computation just once, and try to share that across the forks. This ensures we do the expensive initialization only once.
5ce64cf to
931eb2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason this is a TCS and not an AsyncLazy?
We're seeing a performance issue in Razor projects in cohosting scenarios. The first run of the Razor generator is relatively slow, and so ideally we wouldn't have that happen more than once. However, since multiple features might request compilations for a Razor project during startup in parallel, it's possible that all of those parallel invocations might initialize the generator multiple times if they happen to be different Solution instances. This change tries to ensure that when we're creating a GeneratorDriver for a project when we don't already have one, we'll do that computation just once, and try to share that across the forks. This ensures we do the expensive initialization only once.