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

Performance optimisations on stitchIntoRecord #13

Merged
merged 1 commit into from
Sep 1, 2019

Conversation

far-blue
Copy link
Contributor

This PR suggests some performance optimisations on stitchRecord, as per the discussion in #12. The general approach is:

  • Exit the stitchIntoRecord method early when possible.
  • Remove foreignRecord entries in stitchIntoRecord once they've been matched, where possible.

I've not analysed/improved many-2-many relationships in this PR but I suspect there is possible further improvement in the case of many-2-1 and many-2-many around keying foreign records on a hash of their match fields to prevent multiple scans through the foreignRecords array. However, this would require a larger re-working on the stitching methods.

Remove foreignRecord entries in stitchIntoRecord once they've been matched, where possible.
@far-blue
Copy link
Contributor Author

I'm nervous about these changes because they seem so obvious I've almost convinced myself I've missed something that means these improvements won't work! So please don't just take my word for it that these changes are good in all possible situations. They certainly appear correct in my application but that's not saying much.

All unit tests pass.

@pmjones
Copy link
Contributor

pmjones commented Aug 29, 2019

@far-blue I have taken a quick look. The early-return portions look reasonable, but I am a little uneasy about the unsets. I will do some experimentation here and report back. Thank you very much for putting this together!

@pmjones
Copy link
Contributor

pmjones commented Aug 29, 2019

@far-blue Yes, these all look reasonable. My unease with the unsets was unfounded. In 1:1 and 1:M relationships, the native primary key is specified on the foreign table, which means that no two natives can ever relate to the same foreign; thus, unsetting does not remove a possibly-related record. I expect to merge this today/tomorrow. Thanks again for your good work here!

@pmjones pmjones merged commit 3927b2a into atlasphp:1.x Sep 1, 2019
@far-blue
Copy link
Contributor Author

far-blue commented Sep 1, 2019

Thanks for accepting the PR :)

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