-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Convert tar header struct to class #72472
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
Convert tar header struct to class #72472
Conversation
Simplify return value of async methods (one value instead of tuple). Use nullability where TarHeader is returned or out'd. Move method to get correct entry type to TarHelpers. Reuse it in TarEntry conversion constructor.
|
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsThe internal The fact that it is a struct caused some issues when adding the async functionality. Some examples:
Having it defined as a struct does not help with perf since it is a large type. So changing it to a class shouldn't affect performance much. The main advantage is that I will be able to submit another PR removing all the code duplication (didn't put it all here to avoid creating a huge PR). Additional changes:
|
Do you have any perf tests to back this statement? |
eerhardt
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.
Just a few nits. LGTM otherwise.
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarReader.cs
Outdated
Show resolved
Hide resolved
…is will help with de-duplication in the next PR.
Working on it... Edit: @eerhardt Here are the results - Took some time because I had to build runtime in Before my changes (base commit before this PR changes, b6932fd): After my changes (last commit in this PR, 5bd06d0): ResultsComparer output: |
|
From my chat conversation with @eerhardt: we are seeing fewer allocations, and this might be because the huge structs were being copied to the async methods, but now with a class this doesn't happen. Also, it's possible that converting the non-default strings to nullable, and not assigning an initial value, helped too. |
adamsitnik
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.
It looks much better now, thank you @carlossanlop !
The internal
TarHeaderstruct is used as a member of the publicTarEntryclass. It describes all the fields of a tar header and hosts all the functionality that reads and writes the header into the archive stream buffer.The fact that it is a struct caused some issues when adding the async functionality. Some examples:
Having it defined as a struct does not help with perf since it is a large type. So changing it to a class shouldn't affect performance much. The main advantage is that I will be able to submit another PR removing all the code duplication (didn't put it all here to avoid creating a huge PR).
Additional changes:
TarHelpersthe method that decides if a regular file entry type should be converted to the appropriate target format, and reused it in another location that had the same need.TarHeaderclass. Initialized the mandatory fields, and converted the non-mandatory string fields to nullable.