-
Notifications
You must be signed in to change notification settings - Fork 8
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
Significant inefficiencies in stitchIntoRecord #12
Comments
You had me at O-notation.
Please do! |
My suggestion is to use benchmarking and define some scenarios for this case. PhpBench can help here. |
The most significant improvements with my suggested changes are with 1-2-1 relationships where my own testing has shown massive improvements but I think a more general approach using common uses of Atlas and profiling for bottlenecks would be great :) |
Fixed by #13 |
Hi all,
I'm testing pushing real-world levels of data through a microservice I've written using Atlas and I've noticed some significant inefficiencies in the various stitchIntoRecord methods.
For instance, the OneToOne class method in combination with RegularRelationship's stitchIntoMethods() method basically loops through every nativeRecord in turn and then loops through every foreignRecord to match them up. However, it neither exits early when a match is found nor removed matched foreignRecords. So with 1000 nativeRecords and their associated 1000 foreignRecords you end up with 1,000,000 calls to recordsMatch().
I'd like to suggest that:
I don't think there are further optimisations available for the other relationship types.
In the case of OneToOne the result is a change from O(n^2) to O(2n). In testing with 3000 records in my app this changed execution time from over 2 mins to 5 seconds.
Do these changes sound correct and reasonable or have I missed something? If there's no reason against the changes I'm happy to put together a PR.
One point with these changes will be that in the case of duplicate records the behaviour will change. If there are duplicates foreignRecord entries, where currently the last record that matches in the foreignRecords array will always be assigned with my changes the first will be assigned instead for OneToOne and ManyToOne. If there are duplicate nativeRecord entries, where currently all duplicates will receive the same foreignRecord they will now receive different ones and possibly no match will be found for duplicates in the case of OneToOne and OneToMany as the foreignRecord entries are removed as they are consumed.
Thoughts from anyone?
The text was updated successfully, but these errors were encountered: