-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Avoid running generators when nothing has changed in a compilation tracker. #73897
Changes from all commits
76d435d
c29f51c
1fac8e1
2bb87e1
5c3b329
ed0bfc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -584,6 +584,17 @@ await compilationState.GetCompilationAsync( | |
staleCompilationWithGeneratedDocuments, | ||
cancellationToken).ConfigureAwait(false); | ||
|
||
// Our generated documents are up to date if we just created them. Note: when in balanced mode, we | ||
// will then change our creation policy below to DoNotCreate. This means that any successive forks | ||
// will move us to an in-progress-state that is not running generators. And the next time we get | ||
// here and produce a final compilation, this will then be 'false' since we'll be reusing old | ||
// generated docs. | ||
// | ||
// This flag can then be used later when we hear about external user events (like save/build) to | ||
// decide if we need to do anything. If the generated documents are up to date, then we don't need | ||
// to do anything in that case. | ||
var generatedDocumentsUpToDate = creationPolicy.GeneratedDocumentCreationPolicy == GeneratedDocumentCreationPolicy.Create; | ||
|
||
// If the user has the option set to only run generators to something other than 'automatic' then we | ||
// want to set ourselves to not run generators again now that generators have run. That way, any | ||
// further *automatic* changes to the solution will not run generators again. Instead, when one of | ||
|
@@ -605,6 +616,7 @@ await compilationState.GetCompilationAsync( | |
|
||
var finalState = FinalCompilationTrackerState.Create( | ||
creationPolicy, | ||
generatedDocumentsUpToDate, | ||
compilationWithGeneratedDocuments, | ||
compilationWithoutGeneratedDocuments, | ||
hasSuccessfullyLoaded, | ||
|
@@ -685,11 +697,21 @@ public ICompilationTracker WithCreateCreationPolicy(bool forceRegeneration) | |
if (state is null) | ||
return this; | ||
|
||
// If we're already in the state where we are running generators and skeletons (and we're not forcing | ||
// regeneration) we don't need to do anything and can just return ourselves. The next request to create | ||
// the compilation will do so fully. | ||
if (state.CreationPolicy == desiredCreationPolicy && !forceRegeneration) | ||
return this; | ||
// If we're not forcing regeneration, we can bail out from doing work in a few cases. | ||
if (!forceRegeneration) | ||
{ | ||
// First If we're *already* in the state where we are running generators and skeletons we don't need | ||
// to do anything and can just return ourselves. The next request to create the compilation will do | ||
// so fully. | ||
if (state.CreationPolicy == desiredCreationPolicy) | ||
return this; | ||
|
||
// Second, if we know we are already in a final compilation state where the generated documents were | ||
// produced, then clearly we don't need to do anything. Nothing changed between then and now, so we | ||
// can reuse the final compilation as is. | ||
if (state is FinalCompilationTrackerState { GeneratedDocumentsUpToDate: true }) | ||
return this; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here's the checking point. We have been told that there was an external signal to rerun generators (a save or build) and that it was not the user explicitly clicking on the button that says "dump all generator state and rerun". Since we can see we just did that, we don't need to proceed. |
||
} | ||
|
||
// If we're forcing regeneration then we have to drop whatever driver we have so that we'll start from | ||
// scratch next time around. | ||
|
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.
note: looking at the code below this line is very relevant.
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.
importantly, we only generate the docs when the policy is
GeneratedDocumentCreationPolicy.Create
, but in balanced mode we then immediately transition after this line to .DoNotCreate mode.So the final state will say "i just generated up to date docs, but any forks off of me should reuse the docs and not regenerate them". Those forks will then end up back in the FinalCompilationTrackerState, except this time they will say "i did not just generate the SG docs" as their creation policy on this line was DoNotCreate.