NightOwl888 edited a comment on issue #256:
URL: https://github.com/apache/lucenenet/issues/256#issuecomment-771769423


   > Since `WeakDictionary` is a port of `WeakHashSet` in Java , has anyone 
taken a long hard look at the `WeakDictionary` code to see why it's not more 
performant and why some of it's tests fail in debug mode?
   
   Yes, [Vincent Van Den Burghe looked at this a while 
back](https://lists.apache.org/thread.html/8afa06f330d3fe566bad15a4e408a4e8bd25c9c92a6cbf3bd8136768%40%3Cdev.lucenenet.apache.org%3E)
 and this was a "best effort" that could be done using pure managed code. It 
uses `WeakReference` to allow references to be GC'd, however, the dictionary 
entries still need to be cleaned up after the `WeakReference` dies and therein 
lies the bottleneck. Most read/write operations do a `CleanIfNeeded()` 
operation which isn't very efficient (and may in fact have concurrency issues 
as noted in the link above).
   
   Using native resources is really the only way we can be sure that dictionary 
entries are "removed" as soon as their contained reference goes out of scope. 
`ConditionalWeakTable` does exactly what we need, but in .NET Standard 2.0 it 
is missing 2 of the APIs we need, which is a deal breaker in those 5 cases 
mentioned above.
   
   > Since no version of .NET Framework yet supports .NET Standard 2.1
   
   Microsoft considers [.NET Framework to be 
"finished"](https://github.com/dotnet/standard/issues/859#issuecomment-435985504)
 and there will be no further development on it, including upgrading to .NET 
Standard 2.1. This is a problem that won't go away until everyone moves from 
.NET Framework to .NET 5+, which is now the best upgrade path.
   
   This problem dies with .NET Framework (meaning it will become less of an 
issue over time) and we have a solution that works for now, but is less than 
ideal. Additionally, `WeakDictionary` has been marked internal. Therefore, this 
issue is fairly low priority.
   
   That being said, there are other components of J2N that could benefit 
performance-wise by using native code as well. It would be great if we set up a 
precedent for building and deploying native code with J2N.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to