Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Change logic for how we cache GeneratorDrivers to avoid initialization#81323

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
jasonmalinowski wants to merge1 commit intodotnet:main
base:main
Choose a base branch
Loading
fromjasonmalinowski:generator-initialization-caching-improvements

Conversation

@jasonmalinowski
Copy link
Member

This makes a few general changes to how we cache drivers so we don't re-initialize them multiple times when we're first loading a solution.

  1. Rather than the cache being a ProjectId -> cached driver map, we instead just have the object holding the cached driver held directly by the ProjectState.
  2. Rather than clearing out the cached driver once we think we won't need it, we just continually refresh the cached driver with the latest version. This simplifies the logic and also ensures we won't ever clear something out that we would need later, but still keeps us from holding onto old state.
  3. Rather than explicitly clearing out the initialized driver when we have to rerun generators, we keep it around.

This makes a few general changes to how we cache drivers so we don'tre-initialize them multiple times when we're first loading a solution.1. Rather than the cache being a ProjectId -> cached driver map,   we instead just have the object holding the cached driver held   directly by the ProjectState.2. Rather than clearing out the cached driver once we think we won't   need it, we just continually refresh the cached driver with the   latest version. This simplifies the logic and also ensures we won't   ever clear something out that we would need later, but still   keeps us from holding onto old state.3. Rather than explicitly clearing out the initialized driver when we   have to rerun generators, we keep it around.
// 1. If some other fork of this Solution needs a GeneratorDriver created, it'll have one that's probably more update to date.
// This is obviously speculative -- if it's a really old Solution fork it might not help, but can't hurt for the more common cases.
// 2. It ensures that we're not holding an old GeneratorDriver alive, which itself may hold onto state that's no longer applicable.
this.ProjectState.GeneratorDriverCache.UpdateCacheWithForGeneratorDriver(generatorDriver);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

WithFor

nit: name is odd

publicvoidUpdateCacheWithForGeneratorDriver(GeneratorDriverdriver)
{
ImmutableInterlocked.TryRemove(ref_driverCache,projectId,out_);
_driverCache=AsyncLazy.Create(driver);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Cute. Definitely doc this field to explain this will happen. Ah. I see you did doc this well

// Clear out the cache of any previously initialized GeneratorDriver. Otherwise we might reuse a
// driver which will not count as a new "run" in some of our unit tests. We have tests that very explicitly count
// and assert the number of invocations of a generator.
GeneratorDriverCache.EmptyCacheForProject(projectId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yaay

@CyrusNajmabadi
Copy link
Member

Thanks for this. It's a lot cleaner/clearer!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ToddGrunToddGrunToddGrun left review comments

@CyrusNajmabadiCyrusNajmabadiCyrusNajmabadi approved these changes

Assignees

@jasonmalinowskijasonmalinowski

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@jasonmalinowski@CyrusNajmabadi@ToddGrun

[8]ページ先頭

©2009-2025 Movatter.jp