-
Notifications
You must be signed in to change notification settings - Fork 850
PooledObjectPolicy as abstract base class for avoiding interface call #318
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
Conversation
rynowak
left a comment
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.
Overall this design change looks great!
|
Yes, I prefer this to the dynamic code generation version. |
| public DefaultObjectPool(IPooledObjectPolicy<T> policy, int maximumRetained) | ||
| { | ||
| _policy = policy ?? throw new ArgumentNullException(nameof(policy)); | ||
| _fastPolicy = policy as PooledObjectPolicy<T>; |
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.
This is worth a comment, explaining that this base class was introduced in 2.1 to avoid the interface call
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.
Ah, now I added the comment above. Is the intention still clear or should I move the comment to this line?
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.
Looks good!
|
I'm going to generate this whole class with emit next time you go on vacation |
|
That settles it, I'm never going on vacation again. |
Accesses to this list are not thread-safe because we can be enumerating it on one thread (in Return) while another thread adds to it (in Create). The list is unnecessary because the PredictionEngine will always be "rooted". Either it was being held in memory by someone who got the PredictionEngine from the pool, or it is being held by the ObjectPool itself. So it won't ever be GC'd, and the WeakReference is not doing anything. Also, inherit from PooledObjectPolicy instead of IPooledObjectPolicy, so it can take the "fastPolicy" path in DefaultObjectPool. (See dotnet/extensions#318). Fix dotnet#4981
Accesses to this list are not thread-safe because we can be enumerating it on one thread (in Return) while another thread adds to it (in Create). The list is unnecessary because the PredictionEngine will always be "rooted". Either it was being held in memory by someone who got the PredictionEngine from the pool, or it is being held by the ObjectPool itself. So it won't ever be GC'd, and the WeakReference is not doing anything. Also, inherit from PooledObjectPolicy instead of IPooledObjectPolicy, so it can take the "fastPolicy" path in DefaultObjectPool. (See dotnet/extensions#318). Fix #4981
For discussion see #317
This is the variant Abstract base class, addressing #317 (comment)