Skip to content

Cache semantic models per syntax tree#4203

Merged
davidwengier merged 1 commit intodotnet:masterfrom
davidwengier:CacheSemanticModels
Nov 10, 2020
Merged

Cache semantic models per syntax tree#4203
davidwengier merged 1 commit intodotnet:masterfrom
davidwengier:CacheSemanticModels

Conversation

@davidwengier
Copy link
Member

@davidwengier davidwengier commented Nov 10, 2020

Hopefully this is a mitigation for AB#1241130 before the real work is done in the compiler.

Microsoft Reviewers: Open in CodeFlow

@davidwengier davidwengier requested a review from a team as a code owner November 10, 2020 01:24
@ghost ghost assigned davidwengier Nov 10, 2020
@RussKie
Copy link
Contributor

RussKie commented Nov 10, 2020

@RussKie
Copy link
Contributor

RussKie commented Nov 10, 2020

LGTM, though I'd like to get @chsienki approval.

@RussKie RussKie added the tenet-performance Improve performance, flag performance regressions across core releases label Nov 10, 2020
@codecov
Copy link

codecov bot commented Nov 10, 2020

Codecov Report

Merging #4203 (cd6e5a6) into master (8dccbc0) will decrease coverage by 0.00774%.
The diff coverage is n/a.

@@                 Coverage Diff                 @@
##              master       #4203         +/-   ##
===================================================
- Coverage   98.12512%   98.11738%   -0.00774%     
===================================================
  Files            497         497                 
  Lines         258523      258523                 
  Branches        4492        4492                 
===================================================
- Hits          253676      253656         -20     
- Misses          4089        4105         +16     
- Partials         758         762          +4     
Flag Coverage Δ
Debug 98.11738% <ø> (-0.00774%) ⬇️
production 100.00000% <ø> (ø)
test 98.11738% <ø> (-0.00774%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@davidwengier
Copy link
Member Author

Oh, the AB# thing doesn't work here? You should talk to @Pilchie about that 😁

// The compiler doesn't necessarily cache semantic models for a single syntax tree
// so we will do that here, ensuring we only do the expensive work once per tree.
// We can't cache this at a higher level because generator lifetime is not to be relied on.
var semanticModelCache = new Dictionary<SyntaxTree, SemanticModel>();
Copy link
Member

Choose a reason for hiding this comment

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

This is interesting. We'll definitely fix the semantic model caching, but its a good point that there's no way to cache things in a more general sense. An interesting balance because we don't want you to cache the compilation, syntax trees, etc. (or the semantic model) but there might be things the generator could cache.

Nothing to do with this PR, but an interesting observation 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I mainly wrote the comment because I figured otherwise the first question on the PR would be "why not make this a field?".

Sadly, blindly calling GetSemanticModel, and trying to avoid state, are both super easy traps to fall in to. Luckily I knew about one of them :)

Copy link
Member

@chsienki chsienki left a comment

Choose a reason for hiding this comment

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

LGTM

@davidwengier davidwengier merged commit 7b381e0 into dotnet:master Nov 10, 2020
@ghost ghost added this to the 6.0 Preview1 milestone Nov 10, 2020
@davidwengier davidwengier deleted the CacheSemanticModels branch November 10, 2020 21:43
@RussKie
Copy link
Contributor

RussKie commented Nov 11, 2020

Thank you

@jaredpar
Copy link
Member

Do we have a bug tracknig the fix on the Rsolyn side?

@chsienki
Copy link
Member

Issue is here: dotnet/roslyn#49289

@ghost ghost locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

tenet-performance Improve performance, flag performance regressions across core releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants