Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Rewrite a few more array FCalls in C# - #27603

Merged
jkotas merged 6 commits into
dotnet:masterfrom
jkotas:prepwork
Nov 2, 2019
Merged

jkotas merged 6 commits into
dotnet:masterfrom
jkotas:prepwork

Conversation

@jkotas

@jkotas jkotas commented Nov 1, 2019

Copy link
Copy Markdown
Member

No description provided.

@jkotas

jkotas commented Nov 1, 2019

Copy link
Copy Markdown
Member Author

All affected methods got faster. Here are a few examples for different methods called on new byte[1]:

  • Array.Clear(b, 0, 1) ~20% faster
  • b.GetLength(0) ~12% faster
  • b.GetLowerBound(0) ~35% faster

(These numbers are collected on top of #27554.)

@AaronRobinsonMSFT AaronRobinsonMSFT left a comment

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.

LGTM

Comment thread src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs Outdated
Fix error SA1028: Code should not contain trailing whitespace
@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

@jkotas Heads up. I addressed error "SA1028: Code should not contain trailing whitespace" that was failing and committed directly into the branch.

@GrabYourPitchforks GrabYourPitchforks left a comment

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.

LGTM, but one question on potential overflow scenarios.

Comment thread src/System.Private.CoreLib/src/System/Array.CoreCLR.cs
Comment thread src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs Outdated
@GrabYourPitchforks

Copy link
Copy Markdown
Member

As an aside, is there a test or some other check we can have that verifies that the native structs and the managed structs are in sync? I imagine the more we move traditionally native functionality into the managed world, it increases the chances of them getting out of sync at some point.

@jkotas

jkotas commented Nov 1, 2019

Copy link
Copy Markdown
Member Author

Yes, it would be nice to have it. We have the same problem for number of other structures passed through FCalls. Some of it is covered via checks in vm\mscorlib.h.

@AaronRobinsonMSFT AaronRobinsonMSFT left a comment

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.

LGTM

@jkotas
jkotas merged commit cbe5ac1 into dotnet:master Nov 2, 2019
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static unsafe bool ObjectHasComponentSize(object obj)
{
return GetMethodTable(obj)->HasComponentSize;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why is GC.KeepAlive required in GetMultiDimensionalArrayRank but not here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

All callers ObjectHasComponentSize keep the MethodTable alive by using the object after the calling ObjectHasComponentSize. I will add a comment or a call to GC.KeepAlive to make this clear.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment added in #27668

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.

5 participants