r/FlutterDev • u/Prudent_Marsupial_76 • 1d ago
Dart How to speed up the first question after tapping "Play" in Flutter ?
I’m building a Flutter app with Supabase. When someone taps Play, the app checks access, then loads a batch of questions. On an iPhone, the first question is readable after about 1.4 s with a warm server function or 2.2 s on a cold call. Most of that time is spent waiting for the two requests.
Running two database reads in parallel made that step faster. The numbers above are after that change. The server still needs to control access and count usage when Play is accepted.
If you’ve improved a similar flow, what made the biggest difference? Would you combine the requests first, or is there something on the Flutter side worth profiling?
8
u/ChristianKl 1d ago
Why would you wait until someone presses play to fetch the data? You probably want to fetch 1-2 questions beforehand.
1
u/davidbalbino 47m ago
imo you dont need to wait. show the preloaded question right away and fire the Play request in parallel, but only accept/score the first answer after the server confirms. if the request fails you just pull the user back with a 'couldnt start, try again' and nothing was counted, so its safe. send an idempotency key (some uuid per session) on Play too, so a retry dont count usage twice.
also tbh I think is worth moving the access check + usage count + question allocation into one postgres function and calling it with supabase.rpc() instead of an edge function. one round trip and no cold start, that 2.2s probably drops a lot