Server side vs Client Side for private web apps

At a glance, I see a function called by the client that takes an Excel file object as an argument, reads it with pandas, and adds one row to a table for each row in the Excel file.

It is possible that a good part of the 2 seconds (if this is what we are still talking about) are spent importing pandas.

Anvil loads the whole app and imports all the server modules every time a server function is called, unless you are using the persistent server option (not available on all plans). I haven’t tested it, because I have a plan with persistent server, so I don’t care (much) about package import times, but chances are that pandas is a large package and takes some time to import.

Some time could be spent also adding the rows, if there are many rows in the file. Make sure you have accelerated tables enabled in the app settings, so adding rows will be faster. Also, try to wrap all the row-adding cycle in a transaction (or simply add the transaction decorator to the function), so everything will happen in one single transaction, rather than creating a transaction per row.

Some tips for troubleshooting the speed:

  • Try to create an http endpoint that does nothing in a new app. This will give you the baseline.
  • Try to add the import of pandas to the new app. This will tell you if pandas is slow to import.
  • Try with Excel files with 1, 10 or 100 rows. This will tell you about the impact of adding many rows in the same call.
  • Try with and without transaction.
2 Likes