-
Notifications
You must be signed in to change notification settings - Fork 847
Stop eagerly evaluating seqs (revert parts of #5348, #5370) #5947
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
Conversation
|
I will check with my employer and hopefully sign the CLA tomorrow. |
|
@Smaug123 Thanks for this! Looks like there is a CI failure: |
Got the order wrong for the output of `countBy`.
|
I just realised that |
groupBy test was bad: it assumed (ridiculously) that groupBy wouldn't iterate the original sequence even though it somehow knew the groups in the sequence.
|
I think this is ready to go, but I'd appreciate someone checking the logic of the tests just to make sure they're "obviously right". |
saul
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM cc @forki
|
Thanks for taking care of this and again: apologies. |
cartermp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Smaug123
|
@dsyme can you review/merge/push an updated package? I don't know why one was created a week ago, but apparently that happened. |
|
Wierdly enough I am in two minds about this. I sort of like the isEmpty optimization because it saves an allocation nd initialization of the dictionary/hashset for the common but special case of an empty sequence. isEmpty special cases array, list and ICollection, which do not require allocations. It should be noted that isEmpty merely calls MoveNext one time on the getEnumerator, it doesn't enumerate the entire sequence. So we trade an extra dictionary initialization on empty array/list sequences with an extra allocation on non Array/List/ICollection collections. In the end, I can imagine the isEmpty optimization coming back. I seem to remember receiving a bunch of PRs with it a while back. In the spirit of a special case must be clearly necessary to be special I am prepared to accept this change to unspecial case empty sequences. Anyway, the code changes and tests look fine. If accepted the change will make it into the Dev 16 preview 2 release. For sure this doesn't need a re-release of FSharp.Core until then. |
|
It’s a regression seen due to releasing prior to any VS 2019 preview. Why would we not release this ASAP? It is quite some time before Preview 2 as well. |
|
@cartermp is it broken? Can you even measure the difference? What no longer works? |
|
Yes, the checks for Seq introduced a regression: #5942 and fsprojects/FSharp.Data.SqlClient#319 It's not clear why an FSharp.Core was even released, but I suppose it's good that the regression was caught now rather than in the middle of an escrow. |
|
@KevinRansom It is a genuine regression. Any initialisation your sequence performs is now done twice. If that initialisation is expensive (e.g. opening a connection to a database), and/or side-effectful (as cannot be ruled out in an impure language like F#), or if the first element of the sequence is expensive to compute, then you'll get slow or incorrect results. Moreover, one would never expect a call to For what it's worth, I am skipping FSharp.Core v4.5.3 and falling back to 4.5.2 because of this regression; it's too painful to thread custom |
|
@KevinRansom just to be crystal clear this has caused test failures and performance regressions in production code at G-Research. It absolutely is a bug, and it’s contrary to what you’d expect from a Seq (i.e. entirely lazy until enumeration). |
… (dotnet#5947) * Fix and tests, unbuilt and untested * Correct one of the tests Got the order wrong for the output of `countBy`. * Repair the groupBy test groupBy test was bad: it assumed (ridiculously) that groupBy wouldn't iterate the original sequence even though it somehow knew the groups in the sequence.
This is to fix #5942 . (My first PR to VisualFSharp; let me know if I've done anything wrong.) I've left most of the changes introduced by the rogue PRs mentioned in that ticket; just reverted the Seq-specific changes.
I'm relying here on the continuous integration to actually run these tests, because my home setup remains unable to build the compiler.