Skip to content

Conversation

@cartermp
Copy link
Contributor

@cartermp cartermp commented May 29, 2019

Another one found by removing the IVT to FSharp.Editor. I don't see why AgedLookup is necessary here, so this replaced it with a Dictionary.

Also removes dead code.

type Provider(xmlIndexService:IVsXMLMemberIndexService) =
/// Index of assembly name to xml member index.
let mutable xmlCache = new AgedLookup<VsThreadToken,string,IVsXMLMemberIndex>(10,areSimilar=(fun (x,y) -> x = y))
let cache = Dictionary<string, IVsXMLMemberIndex>()
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be a ConcurrentDictionary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. At least the previous data structure isn't a concurrent one, and AFAIK it's not really a scenario where multiple threads are calling into this routine concurrently.

Copy link
Contributor

Choose a reason for hiding this comment

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

@cartermp it's probably worth taking a lock, or using concurrent dictionary. We aren't actively requiring ui thread only, so multi threaded use of the IDocumentionBuilder will eventually occur.

Copy link
Contributor

Choose a reason for hiding this comment

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

@cartermp the aged lookup is a weak reference fix sized cache. Dictionary is not, I assume we believe this won't cause a problem, because the lifetime of this dictionary is quite short.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll look into that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that there doesn't seem to be anything about AgedLookup that helps a multi-threaded scenario, so really the difference here is:

  • O(1) lookup time instead of O(n), which AgedLookup has
  • Strongly-held data rather than a max of 75 items at a given time

Copy link
Contributor Author

@cartermp cartermp Jun 1, 2019

Choose a reason for hiding this comment

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

I think using a concurrent data structure here is probably not the right call at all. The service isn't concurrent as far as I can tell, as this cache exists inside a type that resides inside a ConditionalWeakTable bound to documentationBuilderCache, a module-level value. I think if we were multi-threaded then making this specific cache a concurrent dictionary would be the least of our problems

@forki
Copy link
Contributor

forki commented May 30, 2019

What even is AgedLookup?

@cartermp
Copy link
Contributor Author

@forki AgedLookup is, as far as I can tell, an older map-like data structure that has an LRU eviction policy and a default of 75 items before it starts evicting. It's also used in the compiler and compiler service.

@forki
Copy link
Contributor

forki commented Jun 1, 2019 via email

@cartermp
Copy link
Contributor Author

cartermp commented Jun 1, 2019

@cartermp cartermp changed the title Replace AgedLookup with Dictionary in XML doc generation Replace AgedLookup with Dictionary in XML doc generation and removes dead code Jun 1, 2019
@cartermp cartermp changed the title Replace AgedLookup with Dictionary in XML doc generation and removes dead code Replace AgedLookup with Dictionary in XML doc generation and remove dead code Jun 1, 2019
@KevinRansom KevinRansom merged commit 3a3d6ed into dotnet:master Jun 2, 2019
@dsyme
Copy link
Contributor

dsyme commented Jun 14, 2019

Another one found by removing the IVT to FSharp.Editor. I don't see why AgedLookup is necessary here, so this replaced it with a Dictionary.

Why doesn't this change introduce a memory leak? The DIctionary will just grow and grow, won't it, never releasing the IVsXMLMemberIndex?

@cartermp
Copy link
Contributor Author

Since the object that owns the dictionary resides in a ConditionalWeakTable its lifetime might be a bit different. But if we're still concerned given that then it's easy enough to just add a check for size and clear when it's reached.

nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Jan 26, 2022
…ead code (dotnet#6900)

* Replace AgedLookup with Dictionary in XML doc generation

* Try remove unecessary stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants