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

Implement efficient Array.IndexOf - #4977

Merged
jkotas merged 3 commits into
dotnet:masterfrom
MichalStrehovsky:structOnlyEquals
Nov 21, 2017
Merged

jkotas merged 3 commits into
dotnet:masterfrom
MichalStrehovsky:structOnlyEquals

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

This is the remainder of #4935.

We special case a couple methods on Array to avoid allocating a full EqualityComparer per each array type. This saves 22 kB on hello world (comparers for a bunch of primitive types and enums).

Same as in #4935 - we restrict the optimization to non-shared value types. On Project N we would also optimize shared valuetypes, but these are rare enough that it's probably not worth building the infrastructure for.

Fixes #763.

}
case "Array":
{
if (methodName == "GetComparerForReferenceTypesOnly")

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.

Nit: It would be nice to not have these intrinsics on Array. Array has a ton of random stuff in it. The less random stuff is dumped into it, the better. I think EqualityComparerHelpers would be a better place for them. (This would need to be adjusted in ProjectN too, of course.)

@jkotas jkotas 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.

Thanks

This is the remainder of dotnet#4935.

We special case a couple methods on Array to avoid allocating a full EqualityComparer per each array type. This saves 22 kB on hello world (comparers for a bunch of primitive types and enums).

Same as in dotnet#4935 - we restrict the optimization to non-shared value types. On Project N we would also optimize shared valuetypes, but these are rare enough that it's probably not worth building the infrastructure for.

Fixes dotnet#763.
@jkotas
jkotas merged commit 48b2ad6 into dotnet:master Nov 21, 2017
@MichalStrehovsky
MichalStrehovsky deleted the structOnlyEquals branch November 21, 2017 20:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants