Skip to content

UnrechableBlocksOptimizer has bad performance #90717

Closed

Description

@Youssef1313

Description

image

image

It looks like there are repeated called to FoldedInstructions.IndexOf where CPU spends most of its time in?

idx = FoldedInstructions.IndexOf (instruction);

It might be more efficient to build a dictionary that maps instruction to index and use that instead of IndexOf?

Reproduction Steps

Expected behavior

Actual behavior

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. ghost added
    untriaged
    on Aug 17, 2023
  2. ghost added
    needs-area-label
    on Aug 17, 2023
  3. Youssef1313 commented on Aug 17, 2023

    @Youssef1313
    MemberAuthor

    I randomly paused the debugger while running the linker, and it was on this line. This is also where it spends most of its time per the performance trace.

    image

    Here, FoldedInstructions has 22542 elements. So a dictionary should be a lot better than linear search.

    One more note that a dictionary could even be avoided. The instruction index is only calculated to check whether it's in a specific range, and this range is always VERY small. We could just loop through this small range. Note that this small range is either single instruction, two instructions, or maximum three instructions (IsJumpTargetRange (i - 2, i)).

  4. Youssef1313 commented on Aug 17, 2023

    @Youssef1313
    MemberAuthor

    @vitek-karas @sbomer Can you please take a look at this? This should hopefully improve the performance a lot

  5. ghost added
    in-pr
    on Aug 17, 2023
  6. added
    area-Tools-ILLink
    and removed
    needs-area-label
    on Aug 18, 2023
  7. ghost removed
    in-pr
    on Aug 18, 2023
  8. ghost removed
    untriaged
    on Aug 18, 2023
  9. ghost locked as resolved and limited conversation to collaborators on Sep 18, 2023
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-Tools-ILLink

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions