Skip to content

[WIP] Remove ToArray calls on MemoryStream #3797

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

Closed
wants to merge 1 commit into from
Closed

Conversation

Mpdreamz
Copy link
Member

@Mpdreamz Mpdreamz commented Jun 4, 2019

and try to reuse .Buffer, new serializer can handle any padding at the end.

@Mpdreamz Mpdreamz added the v7.0.0 label Jun 4, 2019
@Mpdreamz Mpdreamz requested review from codebrain and russcam June 4, 2019 09:12
@Mpdreamz
Copy link
Member Author

Mpdreamz commented Jun 4, 2019

Working on a continuation of this PR where I update our RecyclableMemoryStream with recent changes from https://github.com/microsoft/Microsoft.IO.RecyclableMemoryStream which actually implements TryGetBuffer() rather then falling back to its base MemoryStream implementation.

Something in the implementation of TryGetBuffer() seems off, either it needs to account for offset or the length is not correct if we are reusing blocks.

Some more investigation is needed

if (!ms.TryGetBuffer(out var buffer) || buffer.Array is null)
return ms.ToArray();

return buffer.Array;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to call TryGetBuffer on a RecyclableMemoryStream? It looks like this method is not overloaded.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's safe in the sense that it works but see my comment on the PR, updating to a later version that actually implements it yields some problems under heavy usage.

I have a feeling it sometimes writes at an offset which trygetbuffer does not take into account, not been able to trap it yesterday though

@russcam russcam changed the title Remove ToArray calls on MemoryStream [WIP] Remove ToArray calls on MemoryStream Jul 16, 2019
@russcam
Copy link
Contributor

russcam commented Aug 27, 2019

Is this still waiting on some changes, @Mpdreamz?

@Zyklop
Copy link

Zyklop commented Oct 30, 2019

@Mpdreamz In a performance analysis, I found this to be a problem in our use-case. Do you need some help, or testing assistance? I think it could make a noticeable difference in performance.

@Mpdreamz Mpdreamz mentioned this pull request Oct 31, 2019
@Mpdreamz
Copy link
Member Author

Hi @Zyklop we are meeting as a team next week in person and spending some time doing some performance deep dives.

I've opened #4191 and #4172 as continuations of this branch.

It does not tackle everything we want to investigate but its a first step.

If you like to share your analysis results feel free to email me them to ml at elastic.co, more data/visuals to look at the better.

Any testing you can do is helpful and appreciated as always, keep an eye out next week.

@Mpdreamz
Copy link
Member Author

Closing this as its out of date.

@Mpdreamz Mpdreamz closed this Oct 31, 2019
@Mpdreamz Mpdreamz deleted the 7x/to-array branch October 31, 2019 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants