Skip to content

HashData stream one-shots can special case some stream types #64173

Closed

Description

@vcsjones

The new HashData one shots that accept a Stream as input can special case some stream types by deferring to the ReadOnlySpan<byte> one shots where the stream is known to be backed by contiguous memory. For example, MemoryStream's TryGetBuffer.

Doing this would give a few benefits:

  1. They would be truly non-allocating.
  2. Throughput will be higher since it boils down a single p/invoke (usually) instead of reading from the stream in chunks and updating.

This issue is to track the implementation of that.

Activity

  1. added this to the 7.0.0 milestone on Jan 24, 2022
  2. self-assigned this
    on Jan 24, 2022
  3. ghost added
    untriaged
    on Jan 24, 2022
  4. stephentoub commented on Jan 24, 2022

    @stephentoub
    Member

    can special case some stream types

    It can. Should it? How common will it be to use those streams with this method?

  5. vcsjones commented on Jan 24, 2022

    @vcsjones
    MemberAuthor
  6. vcsjones commented on Jan 24, 2022

    @vcsjones
    MemberAuthor

    I would agree though that the majority of uses are a FileStream or some kind of network stream.

  7. vcsjones commented on Jan 24, 2022

    @vcsjones
    MemberAuthor

    I think my biggest "iffy" on doing this actually is that it will have the observable affect of not advancing the stream if we use TryGetBuffer, unless we explicitly set Position after using TryGetBuffer.

  8. stephentoub commented on Jan 24, 2022

    @stephentoub
    Member

    I think my biggest "iffy" on doing this actually is that it will have the observable affect of not advancing the stream if we use TryGetBuffer, unless we explicitly set Position after using TryGetBuffer.

    You would need to set the position after. You'd also need to constrain it to exactly typeof(MemoryStream) and not any streams derived from it.

    I'm not convinced this is a worthwhile change. All of the cases you cited involve a client that has a strongly-typed MemoryStream and can just as easily call GetBuffer and call the ROS-based HashData.

  9. vcsjones commented on Jan 24, 2022

    @vcsjones
    MemberAuthor

    I'm not convinced this is a worthwhile change.

    Fair enough, I'll close this out then. We can re-open it if any new evidence emerges that this is worth pursuing.

  10. removed their assignment
    on Jan 24, 2022
  11. ghost locked as resolved and limited conversation to collaborators on Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Securityuntriaged

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions