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

Improve performance of UnmanagedMemoryStream #93766

Merged
merged 2 commits into from
Oct 20, 2023

Commits on Oct 20, 2023

  1. Improve performance of UnmanagedMemoryStream

    UnmanagedMemoryStream used Interlocked operations to update its state to prevent tearing of 64-bit values on 32-bit platforms. This pattern is expensive in general and it was found to be prohibitively expensive on recent hardware..
    
    This change removes the expensive Interlocked operations and addresses
    the tearing issues in alternative way:
    - The _length field is converted to nuint that is guaranteed to be
      updated atomically.
    - Writes to _length field are volatile to guaranteed the
      unininitialized memory cannot be read.
    - The _position field remains long and it has a risk of tearing. It is
      not a problem since tearing of this field cannot lead to buffer
      overruns.
    
    Fixes dotnet#93624
    jkotas committed Oct 20, 2023
    Configuration menu
    Copy the full SHA
    557306e View commit details
    Browse the repository at this point in the history
  2. Add comment

    jkotas committed Oct 20, 2023
    Configuration menu
    Copy the full SHA
    b6a9c2d View commit details
    Browse the repository at this point in the history