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

Enumerable improvements [WIP] - #2237

Closed
JonHanna wants to merge 23 commits into
dotnet:masterfrom
JonHanna:EnumerableImprovements
Closed

Enumerable improvements [WIP]#2237
JonHanna wants to merge 23 commits into
dotnet:masterfrom
JonHanna:EnumerableImprovements

Conversation

@JonHanna

@JonHanna JonHanna commented Jul 3, 2015

Copy link
Copy Markdown
Contributor

Fixes #2238

Changes to System.Linq.Enumerable, focusing on reducing the size of loops and on short-circuiting when an existing test points to a short-circuit opportunity. Also adds tests.

JonHanna added 21 commits July 2, 2015 15:12
confirm number of matches equals 1" to "find match, then confirm there
isn't another". Allows for slight performance improvement in 0-match
and 1-match case as loop does less work, and great improvement in many-
match case as evaluation can short-circuit.
@JonHanna JonHanna changed the title Enumerable improvements [WIP Enumerable improvements [WIP] Jul 3, 2015

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.

I'm not sure this change to hide the check-and-throw in a method is an improvement. I agree it helps clean up the code, but in the past I believe I've seen this have implications on inlining, so while this could be a small readability improvement, I think it's possible it could also be a small performance hit. I could be remembering incorrectly, or maybe it's so small in this context that it doesn't matter, but it makes me hesitate.

Regardless, I'd prefer to see such a change separated out into its own PR so that it can be more easily evaluated on its own.

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.

With small enough methods a reason for doing it can be precisely to encourage inlining (if the result is that the containing method drops below the jitter's threshold). I think you've a good point about it being in a different PR though. I shall revert this particular commit soon.

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.

I'd actually thought it would make things worse, as I've seen the JIT refuse to inline methods that contain throw, and I thought it would refuse to inline these helpers because of that, thus we'd actually be increasing the number of function calls that couldn't be inlined. But, I just checked and tried it out, and it appears at least the VS2015 x86 and x64 JITs are able to inline methods with throws in some cases, just not in others (e.g. https://github.com/dotnet/coreclr/blob/master/src/jit/importer.cpp#L12588-L12612), and these helpers are actually able to be inlined, at least in my experiments.

In any event, thanks for separating them out. Since we'd be changing such error checking paths, I'd also hope to see tests in place that would exercise all of those checks being changed.

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.

The 'D' here on the first element is pretty sublte and easy to miss or even accidentally remove, at which point the test changes. How about explicitly typing the array, i.e. new double[] instead of new []?

@stephentoub

Copy link
Copy Markdown
Member

cc: @VSadov, @terrajobst, @KrzysztofCwalina

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.

I do not think former version supported Reset. It is better to not introduce it because in will or will not work depending on underlying source which would be inconsistent and hard to program against. More so, once it is supported it will be hard to take back if future optimizations cannot support Reset.
Generally Linq iterators are not supporting reset. So it is better to not expand the feature surface here.

@VSadov

VSadov commented Jul 6, 2015

Copy link
Copy Markdown
Member

As a general note, I think this would go better in the following order:

  1. tests
  2. Unobservable optimizations - fewer branches, loop unrolling, strength reduction and the like.
  3. Changes that come with behavior differences like short-circuiting or different strategy of calling to source methods. What makes these different is that in addition to perf impact, there is some degree of breakage risk which is harder to measure or estimate.

@stephentoub

Copy link
Copy Markdown
Member

@hackcraft, what do you think of @VSadov's suggested plan of attack here? I think it'd make sense to close out this PR and submit PRs instead for each of his numbered items in the order he recommends (potentially splitting into further PRs if deemed appropriate). Hopefully 1 and 2 would go through without much issue, and then we can have the more difficult conversations around 3.

@JonHanna

JonHanna commented Jul 9, 2015

Copy link
Copy Markdown
Contributor Author

I was actually planning to submit 3 PRs in parallel for those three cases, but won't look at this until the weekend.

JonHanna added a commit to JonHanna/corefx that referenced this pull request Jul 12, 2015
Tests originally commited as part of pull-request dotnet#2237
moved out into separate pull-request.
@JonHanna

Copy link
Copy Markdown
Contributor Author

I was actually planning to submit 3 PRs in parallel for those three cases, but won't look at this until the weekend.

And of course, that's a silly idea, because doing them in parallel means either committing code without tests, which is backwards, or else branching the branches for the other two PRs of the branch in #2326 which has its own issues.

Let's look at the tests, as per #2326. Then I'll split off the other two aspects of this, and close this PR.

JonHanna added a commit to JonHanna/corefx that referenced this pull request Jul 13, 2015
Tests originally commited as part of pull-request dotnet#2237
moved out into separate pull-request.

Consistently favour type names over c# names.

Single element sequences on Min and Max

(What other edge cases should we hit?)

MinValue and MaxValue for element types.

Min & Max with selector

Remove tests on short-circuit/not short-circuit for now.

More skip tests.
JonHanna added a commit to JonHanna/corefx that referenced this pull request Jul 13, 2015
Tests originally commited as part of pull-request dotnet#2237
moved out into separate pull-request.

Consistently favour type names over c# names.

Single element sequences on Min and Max

(What other edge cases should we hit?)

MinValue and MaxValue for element types.

Min & Max with selector

Remove tests on short-circuit/not short-circuit for now.

More skip tests.
JonHanna added a commit to JonHanna/corefx that referenced this pull request Jul 13, 2015
Tests originally commited as part of pull-request dotnet#2237
moved out into separate pull-request.

Consistently favour type names over c# names.

Single element sequences on Min and Max

(What other edge cases should we hit?)

MinValue and MaxValue for element types.

Min & Max with selector

Remove tests on short-circuit/not short-circuit for now.

More skip tests.
@stephentoub stephentoub removed the api-needs-work API needs work before it is approved, it is NOT ready for implementation label Jul 14, 2015
@stephentoub

Copy link
Copy Markdown
Member

@hackcraft, can this be closed now? Has everything you wanted to save from it been separated out?

@JonHanna

Copy link
Copy Markdown
Contributor Author

@stephentoub There's still a bunch of stuff that I'm separating out from it a batch at a time (expect Min and Max optimisations with tests on performance improvement this weekend) but it can still be closed in the meantime.

@JonHanna JonHanna closed this Jul 17, 2015
@stephentoub

Copy link
Copy Markdown
Member

Thanks, @hackcraft.

@karelz karelz modified the milestone: 1.0.0-rtm Dec 3, 2016
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Tests originally commited as part of pull-request dotnet/corefx#2237
moved out into separate pull-request.

Consistently favour type names over c# names.

Single element sequences on Min and Max

(What other edge cases should we hit?)

MinValue and MaxValue for element types.

Min & Max with selector

Remove tests on short-circuit/not short-circuit for now.

More skip tests.


Commit migrated from dotnet/corefx@f8faadf
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.

8 participants