8000 Zip refactoring by Orace · Pull Request #639 · morelinq/MoreLINQ · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Zip refactoring #639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 0 commits into from
Closed

Zip refactoring #639

wants to merge 0 commits into from

Conversation

Orace
Copy link
Contributor
@Orace Orace commented Nov 4, 2019
  • introduce CustomZip with separate behavior by source (internal)
  • use CustomZip for EquiZip, ZipLongest and ZipShortest
  • add ValueTuple overloads
  • use t4 file to have up to 8 input sequences.

Copy link
Member
@atifaziz atifaziz left a comment

Choose a reason for hiding this comment

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

This refactoring has its heart in the right place from a code reuse and consolidation view, but unfortunately it's much worse than the current implementation as it will allocate an array (of arguments) on each iteration of the loop; for sequences of a thousand elements, it will produce a thousand arrays of garbage. Even if this is solved somehow, there are other sorts of allocations like configurations, paddings and enumerators that would need to be addressed to have (at the very least) the same runtime characteristics as before.

@atifaziz atifaziz changed the title Zip refactoring. Zip refactoring Nov 4, 2019
@Orace
Copy link
Contributor Author
Orace commented Nov 4, 2019

I was thinking of removing the ZipSourceConfiguration part (it doesn't handle all the case anyway) and use (3) differents implementation of a ZipIteration strategy that will receive the (wrapped) iterators only once.

The final loop will then look like

while(iterationStrategy.MoveNext())
{
  yield return resultSelector(firstZipIterator.Current, ...);
}

Avoid the wrapping of the enumerator is tough, I don't think they cost so much, am I wrong?

The wrapper will:

  • expose HasNext
  • avoid calls to MoveNext on the wrapped enumerator if the end is already reached
  • avoid calls to Current on the wrapped enumerator if the end is already reached
  • there will be at most 8 of them

@Orace Orace requested a review from atifaziz November 5, 2019 10:46
Copy link
Member
@atifaziz atifaziz left a comment

Choose a reason for hiding this comment

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

This is looking much better from the allocation angle. 👍

use t4 file to have up to 8 input sequences.

This is not something that's been agreed on so kindly revert to the previous arity. This can be discussed in a new issue and a separate PR can follow if and when this one is merged. A refactoring PR shouldn't add to the public surface area of the API unless it's a refactoring of the design (but here it's just the implementation).

@Orace
Copy link
Contributor Author
Orace commented Nov 5, 2019
edited
Loading

use t4 file to have up to 8 input sequences.

This is not something that's been agreed on so kindly revert to the previous arity. This can be discussed in a new issue and a separate PR can follow if and when this one is merged. A refactoring PR shouldn't add to the public surface area of the API unless it's a refactoring of the design (but here it's just the implementation).

Sorry but I need clarification here.
I'm not sure if you want me to revert anything here.
There are tt files in the first commit of this PR.

Do you want me to remove the tt files and keep the generated code ?

@atifaziz
Copy link
Member
atifaziz commented Nov 6, 2019

Do you want me to remove the tt files and keep the generated code ?

Not at all. I just don't want new overloads as part of this PR because this is a refactoring of internals that shouldn't be expanding the public API surface as part of the same commit; it just belongs in a separate commit.

@Orace
Copy link
Contributor Author
Orace commented Nov 6, 2019

I just don't want new overloads as part of this PR

Thank you for the clarifications. I will reduce the overload in this PR and open a new one with the full stuff.

@atifaziz
Copy link
Member
atifaziz commented Nov 7, 2019

Is there a reason for the split in e8925dc?

@Orace
Copy link
Contributor Author
Orace commented Nov 7, 2019

Is there a reason for the split in e8925dc?

Readability of the .g.tt files.
I do the split before reducing the number of overloads.
With the tuple overloads, there is 6 really lookalike block of code.
And to respect the (de facto) convention: file name match method name.

Copy link
Member
@atifaziz atifaziz left a comment

Choose a reason for hiding this comment

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

This is beginning to take good shape. Just needs some final polish, but meanwhile, thanks for all your hard work with this. 👍

@Orace Orace requested a review from atifaziz November 7, 2019 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0