Skip to content

Add missing Stream overloads in DataStreamFromComStream#10857

Merged
lonitra merged 2 commits intodotnet:mainfrom
halgab:DataStreamFromComStream
Feb 21, 2024
Merged

Add missing Stream overloads in DataStreamFromComStream#10857
lonitra merged 2 commits intodotnet:mainfrom
halgab:DataStreamFromComStream

Conversation

@halgab
Copy link
Contributor

@halgab halgab commented Feb 9, 2024

Proposed changes

  • Add optimised overloads to methods DataStreamFromComStream.ReadByte and WriteByte

Customer Impact

  • remove some small arrays allocations

Risk

  • low

Test methodology

  • CI
Microsoft Reviewers: Open in CodeFlow

@halgab halgab requested a review from a team as a code owner February 9, 2024 21:01
@codecov
Copy link

codecov bot commented Feb 9, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (52e9fc4) 72.63168% compared to head (2bf9b7e) 73.20244%.
Report is 63 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #10857         +/-   ##
===================================================
+ Coverage   72.63168%   73.20244%   +0.57075%     
===================================================
  Files           2934        3080        +146     
  Lines         620345      633371      +13026     
  Branches       46946       47403        +457     
===================================================
+ Hits          450567      463643      +13076     
- Misses        161415      166180       +4765     
+ Partials        8363        3548       -4815     
Flag Coverage Δ
Debug 73.20244% <83.33333%> (+0.57075%) ⬆️
integration 18.28778% <0.00000%> (?)
production 46.69772% <83.33333%> (+3.06583%) ⬆️
test 94.99488% <ø> (-2.38067%) ⬇️
unit 43.63494% <83.33333%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Member

@JeremyKuhne JeremyKuhne left a comment

Choose a reason for hiding this comment

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

Thanks for this! Just a minor comment.


public override int ReadByte()
{
Span<byte> oneByteArray = stackalloc byte[1];
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to use the new span constructor, which would be the prefered method:

byte data;
int r = Read(new Span<byte>(ref data));
// ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I hesitated between the two versions and initially chose this one because it didn't require me to initialise the data field.

Copy link
Member

Choose a reason for hiding this comment

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

@halgab you could mark this method as [SkipLocalsInit] if you see that it makes it more efficient (look at sharplap.io).

Copy link
Contributor Author

@halgab halgab Feb 20, 2024

Choose a reason for hiding this comment

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

I tried looking at the il and the assembly in sharplab (here). I can't really interpret the results. I just notice that the asm looks bigger with the attribute. Also, we still have to set data to something despite the attribute.

I guess all those concerns are minor anyway compared to the gains of just defining this method overload properly

@dotnet-policy-service dotnet-policy-service bot added the waiting-author-feedback The team requires more information from the author label Feb 12, 2024
@dotnet-policy-service dotnet-policy-service bot removed the waiting-author-feedback The team requires more information from the author label Feb 13, 2024
@halgab halgab requested a review from JeremyKuhne February 13, 2024 22:05
@elachlan elachlan added the waiting-review This item is waiting on review by one or more members of team label Feb 14, 2024
@lonitra lonitra added ready-to-merge PRs that are ready to merge but worth notifying the internal team. and removed waiting-review This item is waiting on review by one or more members of team labels Feb 16, 2024
Copy link
Member

@JeremyKuhne JeremyKuhne left a comment

Choose a reason for hiding this comment

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

This is good, if you want to further optimize see my comment on [SkipLocalsInit]

@lonitra lonitra merged commit f8177cd into dotnet:main Feb 21, 2024
@dotnet-policy-service dotnet-policy-service bot added this to the 9.0 Preview2 milestone Feb 21, 2024
@dotnet-policy-service dotnet-policy-service bot removed the ready-to-merge PRs that are ready to merge but worth notifying the internal team. label Feb 21, 2024
KlausLoeffelmann pushed a commit to KlausLoeffelmann/winforms that referenced this pull request Mar 5, 2024
* add missing Stream overloads in DataStreamFromComStream

* review feedback
@github-actions github-actions bot locked and limited conversation to collaborators Mar 22, 2024
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.

4 participants