📚 Encyclopedia

Flutter & Mobile · updated 2026-11-30

Perceived load time in a Flutter app and a cold-start disk cache

flutterperformancecachecold-startstale-while-revalidateapi-designdropdown

When an app "takes too long to load", the time is rarely in one place. On the TLDR app (Flutter web and Android against a PHP API) a round of measuring found four separate causes, only one of them a slow query. The fixes are general: fewer round trips before the first paint, paint what you already have, and keep the last answer on disk for the next launch.

Find where the time goes

Put the viewer's state in the same response

If a screen always needs "the thing" plus "my relationship to the thing" (my vote, my flag, my votes on each child), return them together: my_vote, my_flag, and a map my_response_votes: {responseId: vote}. One request replaces 2 + N. Keep the old endpoints, and have the client fall back to them when the field is absent, so an old server or a share-link read that has no viewer still works. Fire-and-forget anything the screen does not need to draw (the view-count ping).

Seed the detail page from the list

The list already holds the row that was tapped. Look it up in the list cache (peekPost(id)), paint the title and body at once with skeletons where the responses will go, and swap in the full object when it arrives. Rules: - A seeded page stays up if the refresh fails (offline), but a real 404 must still replace it with "not found". Have the fetch return (post, gone) so the two cases are distinct. - Any mutation that changes what lists show (pin, archive, delete) must go through the service that owns the list caches and invalidate them. A pin button that called the API directly from the screen left every list showing the old state until a manual refresh. See Singleton services, session caches, and cross-user data leaks in Flutter.

A cold-start cache on disk

In-memory stale-while-revalidate makes tab switches instant, but the first launch still shows a spinner. Persist the small set of things the first screen needs and restore them before the first frame:

Invariants for safety: the disk entries are deleted by the same reset that clears the in-memory caches on every session transition, nothing is saved while an admin is impersonating another user, and anything end-to-end encrypted stays out. The trade is that private but unencrypted content now sits in the cache directory or localStorage until sign-out; decide that on purpose.

To test it, load the release web build twice in headless Chrome, the second time with the API host made unresolvable, and check that the list still paints (Headless Chrome testing gotchas).

Short list first, full list second

A picker with 34 entries is slow to load and slow to read. The pattern that replaced it: - Show a top 10: the 5 most recently used plus the 5 busiest of the rest. "Busiest" counts activity in the last 90 days, with the all-time count as a tie-break; ranking by all-time counts alone keeps dead entries pinned forever. Rank per user. - Never hide the rest for good. A "Show all (N more)" row at the bottom keeps new and never-used entries reachable. - Two requests in order: the short list comes from a database-only endpoint (about 0.1 s), the full list (which needed a slower call to another service) loads after it and becomes the authority. A ranked name missing from the full list is dropped; an empty short list shows the full list outright, which also covers new users and an old server. - "Show all" inside a Flutter dropdown is a menu row with a sentinel value. Selecting it expands the list and reopens the menu; pin that behavior with a widget test, because it depends on framework internals. - Check every surface that lists the same things. The picker was fixed and the complaint came straight back, because a grid of cards on another page loaded the same full list.

Gotchas

See also

Linked from

Sources: tldr memory (perf-post-load, feature-ai-project-top10, bug-pin-stale-lists), tldr posts #1921 #1928 #1929, 2026-11-25..11-29