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

Optimize ArrayBuffer BytesFromStream #38

Merged
merged 3 commits into from
Jul 31, 2017
Merged

Optimize ArrayBuffer BytesFromStream #38

merged 3 commits into from
Jul 31, 2017

Conversation

maartenba
Copy link
Contributor

When stream.Length <= int.MaxValue, the stream can just be read in one
go into a byte[], instead of going through MemoryStream.ToArray(). This
reduces the number of byte[] allocations when initializing.

When stream.Length <= int.MaxValue, the stream can just be read in one
go into a byte[], instead of going through MemoryStream.ToArray(). This
reduces the number of byte[] allocations when initializing.
@oschwald
Copy link
Member

Thanks for the PR! It looks like the tests are failing. Also, please update the tests to ensure both the new code path and the old code path are tested.

@maartenba
Copy link
Contributor Author

Broken test has been fixed.

Right now, the new code path will always be used. Does MaxMind have any test databases that are larger than int.MaxValue (2,147,483,647 bytes / ~2 GB) to use in a test for the original code path?

@oschwald
Copy link
Member

Couldn't we test the old code path by using a stream that doesn't support seeking? Maybe a PipeStream or something?

@maartenba
Copy link
Contributor Author

That could make sense, will see if I can add that.

@maartenba
Copy link
Contributor Author

Added a test for it.

@oschwald
Copy link
Member

Thanks!

@oschwald oschwald merged commit 3dca944 into maxmind:master Jul 31, 2017
oschwald added a commit that referenced this pull request Jul 31, 2017
oschwald added a commit that referenced this pull request Jul 11, 2019
Optimize ArrayBuffer BytesFromStream
oschwald added a commit that referenced this pull request Jul 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants