Skip to content
This repository was archived by the owner on Nov 13, 2026. It is now read-only.

Cache the Rank in GetUpper/LowerBound - #1282

Merged
jkotas merged 1 commit into
dotnet:masterfrom
jamesqo:patch-2
May 17, 2016
Merged

jkotas merged 1 commit into
dotnet:masterfrom
jamesqo:patch-2

Conversation

@jamesqo

@jamesqo jamesqo commented May 16, 2016 •

Copy link
Copy Markdown
Contributor

After dotnet/coreclr#4993, I decided to take a look at the corert implementation of Array.GetLowerBound (and others) to see if any similar optimizations could be made here.

Changes:

  • Array
    • Port original optimizations from coreclr to GetLowerBound, GetUpperBound
    • Cache the rank in these methods as well
    • Array.Copy: Don't get the rank if the EETypePtrs are the same
    • Removed some branching by using a trick with uint wrapping (not sure if this is optimized by the C++ compiler)
  • MDArray
    • Massively reduced the size of the CheckBounds methods (multiple throw new ... means mutliple throws will be in the generated IL, not sure how the AOT compiler handles this)
      • Also avoided some branching using the aforementioned trick
    • Initialize: When you're checking if something is negative, you're really checking if it's highest bit is set. Therefore, we can just AND everything and check if it's != 0 to check if any of the arguments are negative (again, please let me know if this is taken care of by the AOT compiler and if I should revert this)

cc @jkotas

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not use MDArray.cs for CoreRT so there is no good way to test it, and we are on path to eliminate it completely - could you please revert the MDArray related changes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkotas Sure.

@jamesqo jamesqo changed the title Perf improvements for Array/MDArray Perf improvements for Array May 16, 2016
@jamesqo jamesqo changed the title Perf improvements for Array Cache the Rank in GetUpper/LowerBound May 16, 2016
@jkotas

jkotas commented May 16, 2016

Copy link
Copy Markdown
Member

LGTM. Thanks!

@jkotas
jkotas merged commit f46f0da into dotnet:master May 17, 2016
@jamesqo
jamesqo deleted the patch-2 branch May 17, 2016 03:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants