Tips to speed up app startup

Hey guys!
I’ve built an app on Anvil that I’m about to launch commercially, in which I have around 10 client-side forms and 6-7 Server modules; so on each startup, the app takes around 2-3 minutes to load.

The app has around 10 external libraries installed, and each server module calls atleast 3-4 of those libraries.

Does anyone know how I can speed up my app’s startup?

This thread had a great many good suggestions in it:

1 Like

There are a ton of optimization threads on the forum, the vast majority of them dealing with different aspects of optimization. You’ll sadly need to read through most of them to understand what’s happening in Anvil to optimize your app since optimization is app specific, and often unintuitive.

For example, having one server module or 10 makes zero difference to Anvil. It’s what happens inside those server modules at the global level that makes a difference.

One of the few common gotchas is when people use Image components and use the properties pane to load an image into the component directly, instead of putting the image into the Assets and linking it from the component. That’s known to inflate the size of the image and increase loading times of the app.

But otherwise, without way more detail than we have, you’ll have to read through the forum posts and digest what’s already been said about optimization. Lots of good threads out there with a lot of good advice.

2 Likes

I have an app with easily 10x that number of forms and modules, with startup in 10 seconds or so. So I’m sure you can get significant improvements, by paying attention to the details described here in the Forum.

1 Like

I obviously don’t know your exact setup, but things I do to make things appear to load faster.

  1. Move server calls from init to form_show()
  2. Allow things on page to start loading and then populate labels and components with info as it comes in.
  3. If there’s something that requires you to query a data table and then loop through it to perform some operation and then return a result from the server, think about how often the data changes and how up to date it needs to be. If the info doesn’t change often and you can tolerate it using a say 10 minute old snapshot, have a background task that regularly prepares the display data every 10 minutes and saves it as a simple object in a seperate datatable that can be read from the client. Then show user when the last time it was updated and give option to refresh.
3 Likes

Other things that can conceal the load time or make it more tolerable is using a loading message that appears to show progress. you can do this by moving the initial server calls into a background task, reporting status in the task state, and then set label.text= task.state while task.is_running() and setting the icon as a transparent spinny wheel from GIPHY.

2 Likes

Another technique I’ve used is isolating things that don’t require a custom package on a different app that can access the same data tables. The basic python versions are a little snappier. Then make http requests to those apps from the client instead of calling server modules on your intensive apps.

2 Likes