Skip to content

⚡ [#538] Optimize objects list performance#540

Merged
stevenbal merged 3 commits intomasterfrom
issue/538-list-performance
Mar 6, 2025
Merged

⚡ [#538] Optimize objects list performance#540
stevenbal merged 3 commits intomasterfrom
issue/538-list-performance

Conversation

@stevenbal
Copy link
Collaborator

@stevenbal stevenbal commented Mar 3, 2025

Fixes #538

Reduces the response time of GET /api/v2/objects from about ~8.6s to ~0.26s (for a query that returns 5000 objects)

Changes

  • Add django-silk for performance profiling
  • Optimize objects list performance
  • Add basic performance tests with pytest-benchmark

Failing performance test before the changes: https://github.com/maykinmedia/objects-api/actions/runs/13653707936/job/38167868135

@stevenbal stevenbal marked this pull request as draft March 3, 2025 15:53
@stevenbal stevenbal force-pushed the issue/538-list-performance branch 8 times, most recently from db3a6cd to cb45ab2 Compare March 4, 2025 12:04
@stevenbal stevenbal force-pushed the issue/538-list-performance branch 2 times, most recently from b29a2ca to 9c8d3db Compare March 4, 2025 12:28
the filter to only include the objectrecords with the highest index per object was causing major performance degradations, especially in combination with filters on data_attrs.
    Instead of using `Max(...)` together with GROUP BY, we now use Window to figure out the max index per object which is more efficient for larger datasets
assert result.status_code == 200
assert result.json()["count"] == 5000

benchmark_assertions(mean=1, max=1)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure yet if this will be the approach for the future, but at least this prevents performance from degrading to response times worse than 1s for the list endpoint

I want to look at https://docs.codspeed.io/benchmarks/python at some point to see if we can also track regressions.

@stevenbal stevenbal marked this pull request as ready for review March 4, 2025 12:50
Copy link
Contributor

@danielmursa-dev danielmursa-dev left a comment

Choose a reason for hiding this comment

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

Looks good for me, I also tested it locally and it works.

@stevenbal stevenbal merged commit bede7c9 into master Mar 6, 2025
16 checks passed
@stevenbal stevenbal deleted the issue/538-list-performance branch March 6, 2025 09:43
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.

Bad performance when doing API call on /objects

2 participants