Skip to content
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

Release BinaryTokenStreamWriter buffers after use in more cases. #2326

Merged
merged 1 commit into from Oct 21, 2016

Conversation

ReubenBond
Copy link
Member

I'm not certain how useful this change is, since I haven't profiled the difference.

There are several cases where we are taking buffers from the buffer pool and not returning them. This PR eliminates several of those cases.

BinaryTokenStreamWriter.ToByteArray() allocates a new byte array and copies the result, whereas ToBytes() returns the underlying List<ArraySegment<byte>> directly. Hence it is safe to free the buffers after the former (assuming no further use), but not after the latter. ToBytes() should be called AsBytes() or GetBuffers() to reduce any confusion.

Adding an overload to JenkinsHash.ComputeHash which took a List<ArraySegment<byte>> instead of just the current byte[] would further help to reduce allocations.

@gabikliot
Copy link
Contributor

gabikliot commented Oct 21, 2016

Yes, we should try to return, whenever we can (given reasonable effort).
Good catch!

@gabikliot gabikliot merged commit bb57605 into dotnet:master Oct 21, 2016
@ReubenBond ReubenBond deleted the reduce-allocations branch October 21, 2016 04:12
sergeybykov pushed a commit to sergeybykov/orleans that referenced this pull request Oct 27, 2016
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants