-
Notifications
You must be signed in to change notification settings - Fork 760
Change byte allocation to be pooled for performance improvements #4737
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
…formance improvements
|
The StreamsComparer does not have direct unit tests. It could be an idea to add this since it is being directly modified here. |
| byte[] bufferActual = new byte[BUFFER_SIZE]; | ||
| #else | ||
| Span<byte> bufferExpected = stackalloc byte[BUFFER_SIZE]; | ||
| Span<byte> bufferActual = stackalloc byte[BUFFER_SIZE]; |
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.
The BUFFER_SIZE is 4096. That is a bit more than what is recommended for stackalloc, which says up to 1KB. Should this be a concern here?
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.
I agree, even 1KB is on the higher side as I've seen 256 bytes often as a limit to stackalloc.
One other option here could be ArrayPool.
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.
I'll look into ArrayPool - haven't used it before so will investigate and come back later today.
|
Thanks for adding me here @OsirisTerje @mithileshz Welcome back and thank you as well for noticing the room for improvement here 🙂 |
@OsirisTerje There are tests inside EqualConstraintTests inside the region StreamEquality. As this change doesn't change the behaviour of the StreamComparer, I didn't add any extra tests as those would have been covered by the tests in class? |
b696343 to
c642105
Compare
c642105 to
67a1369
Compare
|
4 tests failing. |
src/NUnitFramework/framework/Constraints/Comparers/StreamsComparer.cs
Outdated
Show resolved
Hide resolved
stevenaw
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.
Great work @mithileshz , results are looking promising so far!
I've proactively left a few helpful pointers since you mentioned you were a little new to using ArrayPool.
src/NUnitFramework/framework/Constraints/Comparers/StreamsComparer.cs
Outdated
Show resolved
Hide resolved
src/NUnitFramework/framework/Constraints/Comparers/StreamsComparer.cs
Outdated
Show resolved
Hide resolved
OsirisTerje
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.
lgtm
stevenaw
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.
Fantastic, looks like your change speeds things up and lowers allocations.
LGTM, thanks for your contribution @mithileshz
Fixes #4735