-
Notifications
You must be signed in to change notification settings - Fork 933
Fix ProxyFactory cache #1454
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
Fix ProxyFactory cache #1454
Conversation
Going to include into 5.1 instead. As #1451 now uses completely different approach, I’m going to remove from there changes related to this PR. |
a57a49e
to
41f16d0
Compare
- use a correct implementation of cache - reduce number of allocations of ProxyCacheEntry - reduce memory flow
41f16d0
to
ee06c89
Compare
using NHibernate.Proxy; | ||
using NHibernate.Proxy.DynamicProxy; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3954 | ||
{ | ||
[TestFixture, Explicit("Demonstrates bug impact on cache, but which tests will fail is a bit unpredictable")] | ||
[TestFixture, Explicit("Demonstrates bug impact on cache, but which tests will fail is a bit unpredictable"), Obsolete] |
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.
Had to mark it as obsolete as ProxyCache
class now is marked obsolete
private int _hashCode1; | ||
private int _hashCode2; | ||
|
||
private static readonly FieldInfo InternalCacheField = | ||
typeof(ProxyCache).GetField("cache", BindingFlags.Static | BindingFlags.NonPublic); | ||
typeof(ProxyFactory).GetField("_cache", BindingFlags.Static | BindingFlags.NonPublic); |
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.
The field has moved to ProxyFactory
ProxyCache has a weird, inefficient and incorrect implementation. Replaced with just ConcurrentDictionary.
Removed unnecessary collections manipulations to get some perf boost.
Also, previously there were 4 instances of ProxyCacheEntry created per one call to CreateProxyType. But the constructor of ProxyCacheEntry is expensive in terms of both memory and CPU.