Skip to content

Optimize Half.CompareTo #43117

Closed
Closed

Description

@hrrrrustic

There is a same problem as mentioned here. In the worst case there can be 8 calls to IsNaN() due to two NaN-checks at the beginning of all operators

 public int CompareTo(Half other)
        {
            if (this < other) 
            {
                return -1;
            }

            if (this > other)
            {
                return 1;
            }

            if (this == other)
            {
                return 0;
            }

            if (IsNaN(this))
            {
                return IsNaN(other) ? 0 : -1;
            }

            Debug.Assert(IsNaN(other));
            return 1;
        }

Seems like simple operators inlining should help

Activity

  1. added
    tenet-performance
    on Oct 6, 2020
  2. added
    untriaged
    on Oct 6, 2020
  3. removed
    untriaged
    on Oct 9, 2020
  4. added this to the Future milestone on Oct 9, 2020
  5. dotnet-policy-service commented on Apr 10, 2025

    @dotnet-policy-service
    Contributor

    Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

    This process is part of our issue cleanup automation.

  6. added
    backlog-cleanup-candidate
    on Apr 10, 2025
  7. dotnet-policy-service commented on Apr 24, 2025

    @dotnet-policy-service
    Contributor

    This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

  8. removed this from the Future milestone on Apr 24, 2025
  9. 1 remaining item

  10. removed
    backlog-cleanup-candidate
    on Apr 25, 2025
  11. added
    help wanted
    tenet-performance
    and removed
    tenet-performance
    untriaged
    on Apr 25, 2025
  12. dotnet-policy-service commented on Apr 25, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-runtime
    See info in area-owners.md if you want to be subscribed.

  13. added this to the Future milestone on Jul 14, 2025
  14. added
    in-pr
    on Jul 23, 2026
  15. added a commit that references this issue on Jul 24, 2026
    186b7ac
  16. added a commit that references this issue on Jul 26, 2026
    16f0437
  17. locked and limited conversation to collaborators on Oct 19, 2026
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.Runtimehelp wantedin-prtenet-performance

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions