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] Improve performance of canonical sorting methods #1730

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

grubolsch
Copy link
Contributor

Context

I was in this class for another ticket and saw some performance opportunities.

Changed

We currently first loop trough all places for both getPlacesWithMostEvents() and getOldestPlace(), and then sort the arrays based on some field.
By directly comparing event counts, we avoid the need to sort the array, reducing complexity, and also lowering the RAM usage because we don't build a tmp array to sort and then throw away..

Because sorting in PHP uses quicksort, which is O(n log n).
This means this change reduces the complexity to a linear O(n)

We currently first loop trough all places, and then sort the arrays based on some field.
By directly comparing event counts, we avoid the need to sort the array, reducing complexity, and also lowering the RAM usage because we don't build a tmp array to sort and then throw away..

Because sorting in PHP uses quicksort, which is O(n log n). This means this change reduces the complexity to a linear O(n)
@grubolsch grubolsch changed the title [performance] mprove performance of canonical sorting methods (see details commit) [performance] Improve performance of canonical sorting methods Jul 8, 2024
Copy link
Contributor

@LucWollants LucWollants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement.

I must admit that with changes like these I always like to see timings to avoid premature performance optimisations.

@grubolsch grubolsch merged commit d477892 into master Aug 6, 2024
8 checks passed
@grubolsch grubolsch deleted the performance-improvement-canonicals branch August 6, 2024 12:32
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.

4 participants