immich icon indicating copy to clipboard operation
immich copied to clipboard

Slow cold startup time for mobile app

Open justin13888 opened this issue 1 year ago • 6 comments

The bug

The immich mobile app on Android takes 6-10 seconds regularly for it to startup.

For some context.... Device: Samsung S22 Ultra Number of photos: 1000 ish Misc: I'm using mobile data (20Mbps down)

I think it's fine if it takes a moment for the app to fetch metadata about the photos in the album but it should try to optimistically display all local photos, and previously cached photos (if possible). That'd be a much better user experience.

If any dev is able to give some insight as to the reasons for these behaviours, I would love to know. If the issue isn't isolated, I could make a PR

The OS that Immich Server is running on

Ubuntu 22.04

Version of Immich Server

v1.105.1

Version of Immich Mobile App

v1.105.0

Platform with the issue

  • [ ] Server
  • [ ] Web
  • [X] Mobile

Your docker-compose.yml content

NA

Your .env content

NA

Reproduction steps

1. Force close app or restart device
2. Open immich app

It takes 6-10 seconds on the loading screen before rendering any gallery timelines

Relevant log output

No response

Additional information

No response

### Tasks

justin13888 avatar May 23 '24 21:05 justin13888

I have some more assets in my library (about 180000 in total) and can also confirm that startup time sometimes is all over the place.

What I want to add is, that maybe not pure network connection is the issue as i have same issue when being at home in my 5 GHz WLAN just few meters away from accespoint.

Sometimes load feels like instant, mostly it takes a few seconds, but sometimes it also takes at least a minute. I then switch to use the webinterface in browser on same smartphone which shows pictures instant with no delay.

My guess would be my home server might cause the bottleneck but not sure where, as it is not a banana but also not top tier and mostly idleing:

  • i5-7500
  • 32 GB RAM in total; RAM used by immich currently is machine learning uses 800 MB, microservices 1.3 GB, postgres 2,7 GB, redis 30 MB and server 350 MB; still about 15 GB RAM free so can't be the issue.
  • gigabit lan
  • OS, assets and database on same SSD

Best guess would be postgres is the bottleneck but not sure.

AlmightyFrog avatar May 24 '24 23:05 AlmightyFrog

I have some more assets in my library (about 180000 in total) and can also confirm that startup time sometimes is all over the place.

What I want to add is, that maybe not pure network connection is the issue as i have same issue when being at home in my 5 GHz WLAN just few meters away from accespoint.

Sometimes load feels like instant, mostly it takes a few seconds, but sometimes it also takes at least a minute. I then switch to use the webinterface in browser on same smartphone which shows pictures instant with no delay.

My guess would be my home server might cause the bottleneck but not sure where, as it is not a banana but also not top tier and mostly idleing:

* i5-7500

* 32 GB RAM in total; RAM used by immich currently is machine learning uses 800 MB, microservices 1.3 GB, postgres 2,7 GB, redis 30 MB and server 350 MB; still about 15 GB RAM free so can't be the issue.

* gigabit lan

* OS, assets and database on same SSD

Best guess would be postgres is the bottleneck but not sure.

Glad to hear I'm not the only one.

Database and library storage may be part of the story but based on my hardware and setup, and the fact that the web app also loads the latest images in the timeline significantly faster than the other images, I'm confident there's definitely room for improvement for the mobile app itself.

For the record, my hardware situation is as follows:

  • CPU: AMD Ryzen 7900X
  • 64 GB DDR5 RAM
  • Storage:
  • 900 Mbps wifi connection

As @AlmightyFrog said, hardware shouldn't be the problem because resources are idling anyways.

Even if I "warmed" up the server by scrolling through the whole timeline, the perceived load speed on the web app on another device is obviously faster for me than that of the mobile app.

A few more observations:

  • After not viewing the libraries for a while, the time to first seeing images is visibly slower on both web and mobile
  • On mobile app, I have medium-quality images loaded first.
  • On web app, it seems to load more images simultaneously than mobile app
  • Mobile app clears out images after moving away in timeline

I have a few hypotheses so far:

  • Server does a poor job caching lower-quality images used for timeline.
  • Mobile app loads a medium-quality image first and so server is blocked by generating the medium-quality image first.
  • Mobile app clears loaded photos prematurely

justin13888 avatar May 25 '24 00:05 justin13888

These are a few things I believe should be investigated:

  • Server's caching mechanism of generated assets (e.g. thumbnail, medium-quality images) and original assets
  • Differences between caching of rendered images in web app and mobile app's timeline

For any devs who worked on Immich, would appreciate any guidance or ideas here!

justin13888 avatar May 25 '24 00:05 justin13888

The issue is the way we currently use to initial rendered, which we will need to fetch all data from the server in chunk, parse them all then render. We are working towards a refactor to fetch then render then fetch then render to help with the initial "blank state" on slow network

alextran1502 avatar May 25 '24 01:05 alextran1502

+1 for this!

  • At home with connection to server: Immich starts very fast and i like the experience
  • Not at home (e.g. only cellular connection): Immich starts up slow (feeling like it searches for the server for a long time), which is a bit annoying when quickly trying to send a camera snapshot

So i hope (not being a person knowing much about the technical details) the suggestions above include something like:

  • Immich doesnt care if a server is availalble when opened
  • Immich tries to open up the app (?cached? thumbnails, local files) as fast as possible being available for views/shares
  • "In the background" looks concurrently for a server connection and updates the content in chunks

SHU-red avatar Jun 17 '24 10:06 SHU-red

I'm using the Immich app v1.111.0 build 167 on iOS 17.5.1.

  • When Wi-Fi is ON and there's no server available, the app takes 75 seconds to start.
  • With Wi-Fi OFF, the app starts immediately.
  • The "Automatic foreground backup" and "Automatic background backup" settings don't seem to affect the startup time.

heri3x avatar Aug 15 '24 05:08 heri3x

Was having the same issue. One thing helped is that in network settings on the app, i had as a priority to look for the server on my lan (192.168...) and then to my external domain(immich.example.com), so looking at the logs, the app was searching first for 192 and not finding it(when I'm outside my place not connected to my lan) and timing out with error :ApiException 503: Server is not reachable, and then resuming the connection to my external domain. Switching priorities or even removing the 192 entry fixed the issue like in 50% of the time. Since it's still starts up slow from time to time I think this ticket is still valid.

ptartarian avatar Feb 06 '25 01:02 ptartarian

Is there any work happening on this one? In my opinion, the app should really have a local cache of sort, to load before updating from network.

johansmolinski avatar May 18 '25 16:05 johansmolinski

@johansmolinski yep, actively working on it before stable release

alextran1502 avatar May 18 '25 17:05 alextran1502