-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Pr/various mem optimizations #85
Pr/various mem optimizations #85
Conversation
(cherry picked from commit ff930712ee2c806753f39b7565f50e03a988691f)
(cherry picked from commit 2397f23fc301f4c32408045ab55b19f88ee08599)
…uffer rent in query.
{ | ||
private ArrayPool<T> _owner; | ||
private T[] _array; | ||
private readonly RentIdGen _rentIdGen; |
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 tricky one. Since RcRentedArray now a value type, it will copy values. That means when we dispose it, all copies will remain reference to owner and array.
To fix that we introduce rent id. When rent array, get vacant id and generation. On dispose check the generation. If generation is different, that means this rent was already freed. Otherwise release array and increase the generation.
@@ -55,7 +55,7 @@ private void Balance() | |||
{ | |||
if (_dirty) | |||
{ | |||
_items.Sort(_comparer); // reverse | |||
_items.Sort(_comparison); // reverse |
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.
List.Sort(IComparer) allocates Comparison, so we pass delegate directly to avoid allocations.
Feel free to ask questions if changes or commits are too confusing. PR is big so I recommend to look commit by commit. |
Thank you for your contribution. |
d37a9c6
into
ikpil:pr/wrenge-pr/various-mem-optimizations
This is a big one. It reduces allocations all around the code.