-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
perf(mobile): optimize date loading with batch loading #17240
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
perf(mobile): optimize date loading with batch loading #17240
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM but I will let someone that works on mobile actually merge this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you fix the failing checks?
Introduce DateBatchLoader to reduce the number of database queries by loading dates in batches, improving performance when querying large lists.
72cd31d
to
7a6512b
Compare
@shenlong-tanwen, thanks for checking the PR, fixed linter errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, This is just loading 60K datetime objects, only to use a maximum of 1000 of them and discard the others. But this should fix the slowness for the time being until we get to rework the render grid.
Thank you for the PR. During testing I see this error message poped up
Can you please help double check what caused this? |
Looking at the stacktrace I think the error is not related to the changes. It happens in
Seems like in some situations it tries to take a slice from an empty buffer. Do you have the steps to reproduce the error? I was not able to reproduce it. |
I don't I was testing normal usage and triggered the error, it is quite sporadic so I don't have reproducible steps |
Maybe the issue here because
I could try to update it to |
) * perf(mobile): optimize date loading with batch loading Introduce DateBatchLoader to reduce the number of database queries by loading dates in batches, improving performance when querying large lists. * remove unused totalCount parameter from DateBatchLoader --------- Co-authored-by: Alex <[email protected]>
Description
Introduce DateBatchLoader to reduce the number of database queries by loading dates in batches, improving performance when querying large lists.
My Immich library has 30k assets. On my Fairphone 5 Android phone Add Photos to Album screen takes ~20 seconds before showing anything. The bottleneck is in
_buildRenderList
in /mobile/lib/widgets/asset_grid/asset_grid_data_structure.dart.For
GroupAssetsBy.none
case it queries dates from the database by 1 row for each section. With section size 60 assets and 30k assets in the library that makes 500 separate queries and takes a long time.The optimization in this PR introduce DateBatchLoader to query dates in batches of 60000 rows (1000 sections).
How Has This Been Tested?
Tested on Android only (Fairphone 5).
Before
screen-20250330-144007-compressed.mp4
After
screen-20250330-185714-compressed.mp4
Checklist: