Skip to content

Fix #865: Performance optimization on /artists, /albums and /tracks endpoints

Agate requested to merge performance-optimization into develop

Fix #865 (closed)

After the long discussion in #865 (closed), I've attempted to implement the suggested query plans to improve the response time, however, it only helped marginally. While doing this, I identified that some select_related and annotate calls where resulting in really slow query (especially the tracks count on /artists, so I removed it and used a different approach.

Serialization was also a significant bottleneck (especially with nested objects). I stumbled upon https://hakibenita.com/django-rest-framework-slow which offered some benchmark, and suggested replacing read only serializers with simple functions would bring significant performance improvements.

Based on my tests, this is true, and basically halved the response time on related endpoints. I've also upgraded django rest framework to the latest 3.10.3 release, to benefit from https://github.com/encode/django-rest-framework/pull/6709, which should further increase performance when serializing objects.

All of this was tested on https://open.audio and, in conjunction, reduced the loading time of /api/v1/artists, /api/v1/albums, /api/v1/tracks by a factor 2 or 3.

cc @funkwhale/reviewers-python

Edited by Agate

Merge request reports