codingjoe / django-pictures

Responsive cross-browser image library using modern codes like AVIF & WebP
BSD 2-Clause "Simplified" License
248 stars 20 forks source link

Fix #144 -- Improve DRM serialization performance by filtering source and ratio #148

Closed amureki closed 9 months ago

amureki commented 9 months ago

This is an early draft of a possible direction. I did not go all fancy and did not add tests before I validate this with you.

The manual test on 5000 objects showed me this:

DRF ImageField serialization TIME:  0.15182900428771973
PictureField serialization TIME:  12.384335041046143
PictureField serialization IMPROVED TIME:  3.4643609523773193
codecov[bot] commented 9 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (33562b8) 100.00% compared to head (7c7e943) 100.00%. Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #148 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 13 13 Lines 459 470 +11 ========================================= + Hits 459 470 +11 ``` | [Flag](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | Coverage Δ | | |---|---|---| | [celery](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | `82.34% <0.00%> (-1.98%)` | :arrow_down: | | [cleanup](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | `82.97% <0.00%> (-1.99%)` | :arrow_down: | | [dj4.1](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | `82.97% <0.00%> (-1.99%)` | :arrow_down: | | [dj4.2](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | `82.97% <0.00%> (-1.99%)` | :arrow_down: | | [django-rq](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | `82.34% <0.00%> (-1.98%)` | :arrow_down: | | [dramatiq](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | `82.34% <0.00%> (-1.98%)` | :arrow_down: | | [drf](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | `92.97% <100.00%> (+0.16%)` | :arrow_up: | | [macos-latest](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | `83.19% <0.00%> (-2.00%)` | :arrow_down: | | [py3.10](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | `82.97% <0.00%> (-1.99%)` | :arrow_down: | | [py3.12](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | `82.97% <0.00%> (-1.99%)` | :arrow_down: | | [py3.8](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | `82.97% <0.00%> (-1.99%)` | :arrow_down: | | [py3.9](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | `82.97% <0.00%> (-1.99%)` | :arrow_down: | | [ubuntu-latest](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | `82.97% <0.00%> (-1.99%)` | :arrow_down: | | [windows-latest](https://app.codecov.io/gh/codingjoe/django-pictures/pull/148/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron) | `74.36% <0.00%> (-2.69%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Johannes+Maron#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

amureki commented 9 months ago

@codingjoe got me to the question - should we handle cases when user only provides aspect ratio OR image source? This would be a matter of a couple more elifs, or we also could go with some fancy matcher to solve that.