Speeding up Anvil app initial loading time

Hello all,

I’ve been looking into ways to speed up my app, as the initial loading time is very long. On lower quality connections especially, it can take a long time to load - like when a user is on a spotty cellular connection.

I know minimizing calls to server code is a main one, but I’ve gotten rid of most of those, other than anvil.users.get_user()
Checking out my Chrome Debug console’s Network tab, I’m seeing some pretty massive loading times from my service worker file… my app logo… various CSS files.

Are there any other strategies that can be used to reduce (especially) initial loading times?

There could be two happenings

  • Some expensive operations happening after your app is loaded which delays the opening of the first form

  • Your app just taking a long time to load. This can happen due to some imports in your native library, images or excessive code.

To narrow down the issue, add a print statement to the first line of the startup form/module (nothing should be happening before that print statement).

Then see how long it takes the print statement to appear and the rest of the app to be loaded after that.

I can’t emphasize this enough: measurement is key to improvement. See which steps are happening, and how long each step takes. Then when you try an alternative, you can see how effective that is.

Those are good suggestions, thank you. Though a bit unscientific if we are just eyeballing the print statements. I guess you could include a UTC timestamp at each one, too, and then get the differences between them?

Also I noticed in the GUI there is a “Total import time: xxx ms (y Server calls).”
After making some adjustments in my code and reducing the load time, I also notice I’m getting 1610 ms total import time and 2 server calls. I’m not sure how that stacks up to other apps.

However the Total Import Time seems to fluctuate pretty wildly. I ran it again I got “5323 ms total import time” :thinking:

The total import time increases with every server call you make. However, this won’t have any impact on “initial loading time”

Exactly.

Bear in mind that Client and Server each have their own clocks, so there will likely be a nonzero offset between them. Otherwise, you’ve hit the technique on the head!