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

Using dp rather than recursion for better performance #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

supermeng
Copy link

Cause the performance of current diffArrays is so poor, even a 2000 * 2000 scale would cost too much memory and cpu, and can't get result in time, how about using dynamic programming to optimize it

@supermeng supermeng force-pushed the performance branch 5 times, most recently from d2f707c to cad1ffa Compare April 2, 2022 02:37
@supermeng
Copy link
Author

Solve #72 together

@steida
Copy link

steida commented Jun 3, 2022

@chbrown Are you interested in this PR? Thank you

@chbrown
Copy link
Owner

chbrown commented Jun 6, 2022

@steida Yes, just been busy. And, I appreciate the contribution, but it's a bit off-putting when a PR misrepresents what it's doing; like, the code currently implements dynamic programming, which the comment for diffArrays even calls out by name.

DP and recursion are orthogonal. I do think a loop is the better way. Yes, it works, but the author's misrepresentation doesn't give me a whole lot of faith that it's correct, so I want to go over it closely before I merge it. It's pretty gnarly code — both mine and the PR — so it's tricky to review.

@supermeng
Copy link
Author

with all due respect, the old implementation is just a fake DP, the function recursion call like DP, but the alternatives did not track the struct correctly

@steida
Copy link

steida commented Oct 28, 2022

@supermeng Hi, I am looking for a better algorithm for Evolu https://github.com/evoluhq/evolu/blob/main/packages/evolu/src/query.ts#L50

My use case is simpler because all I need to compare is an array with DB rows (shallow objects). Can you point me to some DP resources? Thank you very much!

@supermeng
Copy link
Author

supermeng commented Oct 31, 2022

@supermeng Hi, I am looking for a better algorithm for Evolu https://github.com/evoluhq/evolu/blob/main/packages/evolu/src/query.ts#L50

My use case is simpler because all I need to compare is an array with DB rows (shallow objects). Can you point me to some DP resources? Thank you very much!

@steida Hi, the main point of array diff it to match the point between i in array1 and j in array2, if i and j is the point, the (i, j) problem could be reduce to (i-1, j-1), if not could be (i-1,j) or (i, j-1), so the DP recursive: F(n)(m) = min(F(n-1)(m), F(n)(m-1), F(n-1, m-1)) + 1; and using a memo to track if (i, j) is used to be compared for array diff.

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.

None yet

3 participants