Skip to content

Review HasFlag calls in hot code paths #13308

Closed

Description

@Youssef1313

HasFlag was optimized in .NET Core 2.1 to not box, but apparently, it's not guaranteed that this optimization will always work. See dotnet/runtime#55455 (comment)

We should replace HasFlag calls (especially ones in hot code paths like pointers) with bitwise AND.

Activity

  1. added
    kind/enhancement
    triage/untriaged
    difficulty/tbd
    area/performance 📈
    on Aug 19, 2023
  2. self-assigned this
    on Aug 19, 2023
  3. Youssef1313 commented on Aug 20, 2023

    @Youssef1313
    MemberAuthor

    Note: It looks like dotnet/runtime#89348 fixes this for .NET 8. So the HasFlag changes in #13309 could be reverted when we move to net8.0/net9.0 a year later.

    Or we could just live with the bitwise AND that is known to be performant and not rely on JIT optimizing HasFlag even when we are net8.0+.

    Edit: Even for net8.0 it seems that the optimization isn't guaranteed. Let's stick with HasFlag for any hot code paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/performance 📈difficulty/tbdkind/enhancementtriage/untriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions