-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
refactor: UpdateDistinct
and Duplicate
operations.
#168
Conversation
11aec79
to
a1ac585
Compare
Distinct
operation.Distinct
and Duplicate
operations.
Pull request was converted to draft
01ff5a6
to
3db3965
Compare
3db3965
to
032aff8
Compare
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.
Nice one 👍 .
This would be the kind of refactoring that would really benefit from having PHPBench so we could see the difference in runtime and memory used by the operations.
I definitely agree. That said, I did the tests locally and the difference is significant! |
I'll find the time at some point to play around with phpbench and see how we introduce it into this project |
This PR:
Duplicate
operation onDistinct
Distinct
operationThe distinct operation was not designed in a lazy way.
The previous version was storing in an array each pair of key-value from the iterator. This is not how we should do that.
The previous version was based on
Reduce
and was traversing the whole iterator before going to the next operation.This is not really optimal and we should update that.
Duplicate
implementation is ready and I'm happy of itBecause of the nature of these operations and their side effects (the
$stack
variable), I'm unable to test them completely, especially thecontinue 2
statement. Infection will most probably detect that without any trouble (Basically, there is no need to go through the whole$seen
array once the inner condition is met).I haven't found a better way to achieve this, maybe the enlightenment will come another day.