Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dotnet/runtime
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: vcsjones/runtime
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: getrandom-linux
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 6 commits
  • 3 files changed
  • 1 contributor

Commits on Jan 10, 2025

  1. Use getrandom on Linux for Guid generation for a 12% speed boost.

    Since Linux 3.17, the syscall `getrandom` can be used to generate bytes from the same entropy source as `/dev/urandom`. This makes it suitable for cryptographic random number generation, something our Guid generator needs.
    
    If `getrandom` is not available because the LibC provided is too old - or if the syscall itself is not available, it will fall back to the previous method of reading from `/dev/urandom`.
    
    `EPERM` is treated like `ENOSYS` - some older Linux kernels returned this when the syscall is not available. The syscall can also be blocked by seccomp. That would be weird, and Docker permits it by default, but if anyone has explicitly gone out of their way to block it, it falls back to using the file descriptor mechanism.
    
    The use of the syscall implementation instead of the file device offers some performance improvements. Anywhere from 10% to 15% in benchmarks.
    
    This does require glibc 2.25. For non-portable builds, that's largely fine. For Microsoft builds, those are (currently) being done on Ubuntu Xenial, which has 2.23. However, it is expected that with .NET 10, the glibc floor is going to change to 2.27 with #109939. If that happens, then the Microsoft portable builds will pick this up as well.
    
    This PR does _not_ change the user-facing `RandomNumberGenerator` that will continue to use `RAND_bytes` from OpenSSL.
    
    | Method         | Toolchain | Mean     | Error   | StdDev  | Ratio |
    |--------------- |---------- |---------:|--------:|--------:|------:|
    | NewGuid        | branch    | 265.1 ns | 0.24 ns | 0.22 ns |  0.87 |
    | NewGuid        | main      | 304.6 ns | 0.16 ns | 0.15 ns |  1.00 |
    |                |           |          |         |         |       |
    | CreateVersion7 | branch    | 293.2 ns | 0.20 ns | 0.18 ns |  0.88 |
    | CreateVersion7 | main      | 335.0 ns | 0.27 ns | 0.23 ns |  1.00 |
    vcsjones committed Jan 10, 2025
    Configuration menu
    Copy the full SHA
    3069f7e View commit details
    Browse the repository at this point in the history
  2. Move label inside ifdef

    vcsjones committed Jan 10, 2025
    Configuration menu
    Copy the full SHA
    a70015c View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    f27df06 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    8aae4bb View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    bef0c2e View commit details
    Browse the repository at this point in the history

Commits on Jan 24, 2025

  1. Configuration menu
    Copy the full SHA
    0aba1d8 View commit details
    Browse the repository at this point in the history
Loading