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

Optimisation of n square array node comparison in LenientJsonArrayPartialMatcher #18

Closed
wants to merge 1 commit into from

Conversation

aymar99
Copy link

@aymar99 aymar99 commented Nov 14, 2023

LenientJsonArrayPartialMatcher performs a comparison of each element in the expected array node with each element in the actual array node, resulting in n^2 complexity for calculating the similarity score before identifying the best matching pairs for comparison. Here is the code link.

I identified an opportunity for optimization in this process. By filtering out identical elements code link from both the expected and actual arrays before applying the n^2 similarity score calculation, we can significantly reduce the complexity. In scenarios where there are only a few mismatches between the expected and actual arrays, this optimization ensures that the n^2 complexity is only applied to those differing elements. The worst-case scenario of n^2 for all elements in the array occurs only if none of the elements match.

For smaller JSONs, the implementation may not exhibit a noticeable difference. However, during testing with larger JSONs containing hundreds of array elements, a significant performance improvement becomes apparent. I have tested this enhancement and created a pull request. I would appreciate it if you could review the pull request and share your thoughts!

@deblockt
Copy link
Owner

Hi @aymar99 , Thanks for this PR.

Sorry for my delayed review, I have see a litle issue on method getElementsWithCount it seem that your never add items on nodeCounter map.
I have rework some code to have lower complexity on the PR #19.

It would be great if you can review it.

Thanks for your help.

@deblockt deblockt closed this Apr 21, 2024
@aymar99
Copy link
Author

aymar99 commented Apr 21, 2024

@deblockt the intention of that method was to get elements by count. I remember making it work as a whole. Some mess up has happened and I have pushed the wrong implementation as you pointed out. Saw your pull request and it has correct implementation of the idea proposed in this PR. Thanks for accommodating the proposal.

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