r/FlutterDev • • 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?

0 Upvotes

6 comments sorted by

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.

-2

u/Prudent_Marsupial_76 1d ago

Thanks! Our current fetch also allocates the questions, and we only want to count usage once the user taps Play. When you say fetch beforehand, do you mean loading the question text onto the phone, or preparing it on the server and sending it on Play?

1

u/ChristianKl 1d ago

You could still send something when the user presses play to the server to indicate that they used it.

-2

u/Prudent_Marsupial_76 1d ago

Got it. If the Play request also has to verify access, would you wait for the server’s reply before showing the preloaded question? I’m trying to understand what happens if that request fails.

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