Skip to content
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

Fix collection-optimized paths for Batch #965

Merged
merged 9 commits into from
Feb 26, 2023
Merged

Fix collection-optimized paths for Batch #965

merged 9 commits into from
Feb 26, 2023

Conversation

viceroypenguin
Copy link
Contributor

The Batch operator contains similar problems to those addressed in issue #943/PR #946. This PR removes all collection optimizations, since they are all based on caching the collection count at initial call instead of run-time.

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.

Good catch and thanks for submitting the PR!

Two things:

  1. There are failing tests that need to be adjusted.
  2. The PR removes all optimisations whereas they should have been moved into the iterator method for similar savings at iteration-time.

@viceroypenguin
Copy link
Contributor Author

  1. Oops. Wilco.
  2. Will restore for now, and issue separate PR to remove them after this PR is pulled in. Discussion to be tabled until then.

@codecov
Copy link

codecov bot commented Feb 9, 2023

Codecov Report

Merging #965 (5057527) into master (aefa90b) will increase coverage by 0.05%.
The diff coverage is 100.00%.

❗ Current head 5057527 differs from pull request most recent head 2d49f5a. Consider uploading reports for the commit 2d49f5a to get more accurate results

@@            Coverage Diff             @@
##           master     #965      +/-   ##
==========================================
+ Coverage   92.49%   92.55%   +0.05%     
==========================================
  Files         113      113              
  Lines        3424     3423       -1     
  Branches     1024     1020       -4     
==========================================
+ Hits         3167     3168       +1     
  Misses        192      192              
+ Partials       65       63       -2     
Impacted Files Coverage Δ
MoreLinq/Batch.cs 98.07% <100.00%> (+3.73%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@atifaziz
Copy link
Member

atifaziz commented Feb 9, 2023

and issue separate PR to remove them after this PR is pulled in

What's the reason behind removing them at all?

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.

Thanks for the follow-up, but I am afraid the test and the implementation don't look right. See my comments.

MoreLinq/Batch.cs Outdated Show resolved Hide resolved
MoreLinq.Test/BatchTest.cs Outdated Show resolved Hide resolved
MoreLinq.Test/BatchTest.cs Outdated Show resolved Hide resolved
MoreLinq.Test/BatchTest.cs Outdated Show resolved Hide resolved
@viceroypenguin
Copy link
Contributor Author

Thanks for the follow-up, but I am afraid the test and the implementation don't look right. See my comments.

Bah! Too many branches on too many projects. :)

MoreLinq/Batch.cs Outdated Show resolved Hide resolved
MoreLinq/Batch.cs Outdated Show resolved Hide resolved
MoreLinq/Batch.cs Outdated Show resolved Hide resolved
MoreLinq/Batch.cs Outdated Show resolved Hide resolved
MoreLinq/Batch.cs Outdated Show resolved Hide resolved
MoreLinq/Batch.cs Show resolved Hide resolved
MoreLinq.Test/BatchTest.cs Outdated Show resolved Hide resolved
[TestCase(SourceKind.BreakingList)]
[TestCase(SourceKind.BreakingReadOnlyList)]
[TestCase(SourceKind.BreakingCollection)]
public void BatchCollectionSmallerThanSizeUsesCollectionCountAtIterationTime(SourceKind kind)
Copy link
Member

Choose a reason for hiding this comment

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

The two could be combined into a effectively single test?

[TestCase(SourceKind.BreakingList)]
[TestCase(SourceKind.BreakingReadOnlyList)]
[TestCase(SourceKind.BreakingCollection)]
public void BatchUsesCollectionCountAtIterationTime(SourceKind kind)
{
    var list = new List<int> { 1, 2 };
    var result = list.ToSourceKind(kind, copy: false).Batch(3);

    list.Add(3);
    Assert.That(result.Consume, Throws.Nothing);

    list.Add(4);
    Assert.That(result.Consume, Throws.TypeOf<BreakException>());
}

@atifaziz
Copy link
Member

@viceroypenguin Any chance we can merge this soon?

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.

Thanks for this!

@atifaziz atifaziz merged commit 0addfbd into morelinq:master Feb 26, 2023
@viceroypenguin viceroypenguin deleted the batch branch February 27, 2023 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants