Impact on CPU Form

I have a form with repeating panel taht require a fair amount of CPU. I would like to optimise it.

What has bigger impact on CPU

  1. Number of components
  2. Lenght of the code in a panel row
  3. Bumber of functions in a bound module?

What would you do to reduce the load?

Without a clone example that shows the problem, I doubt you’ll get specific advice.

In general, you want to time how long tasks are taking and optimize whatever is taking the longest. That will often be whatever is happening most often (e.g. the inner loop in procedural terms).

I don’t think I’ve ever seen an app bottlenecked by CPU on the client-side…

If you are looking to optimize performance, I suggest @stefano.menci’s post here:

1 Like

In my case I’m already fetch only the data I need and use data grid. The problem is that the repeating panel row hat alot of logic that controls good amount of components inside it. Sadly it is important to have that logic.

So my question is more theoretical. Repeating panel has 24 components. 2 small Anvil Extras popovers and in total 1200 lines of code. And some components directly interact with database via data bindings. Some data is saved in module.

Reducing of rows via Data grid reduce the perfomance problemso it’s clearly that panel

I was just wondering where should I start with the work.

Less code, no data bindings or whatever it takes to improve it

Here is the problem. Each row in your repeating panel likely incurs a server call.

Prefetch your data to avoid this and you should be good.

You are bound by network latency, not CPU.

1 Like

Thank you. I will rebuild it to use only fetched data and update of data only via server call.

It’s the first time I’ve decided to use data bindings that write back to data table. I wasn’t aware that such a thing would casue CPU spikes if used for too many bindings.

It’s likely not CPU time, but communications round-trip time, from client to the remote database server and back again. Hence, the recommendation to preload data into the client side.

Edit: also consider turning on Accelerated Tables for this app, if it’s not already on.

I’m using accelerated tables and I load the data from server and save it along with other data in a module. It has to be data bindig that writes the data live back from so many components.

I’m using linked tables and without q.fetch_only I can’t imagineyself loading always the whole data from those links

If it’s writing live, i.e., writing back to data-bound live database rows, each write is still a round trip to the database server.

If it’s practical, you might want to consider binding to client-side lists and dicts, instead of directly to database rows. Then you get to batch up the writes into a single round-trip, which should save many round-trips. And you control when those writes occur.

If your interaction model requires writing frequent, instant updates to the database, for every little change, then that comes with round-trip overhead.

1 Like

I have an app with a repeating panel with the template form with a canvas. For each item it crunches some numbers and draws some shapes. The code has thousands of lines. It can render 20-100 rows per second, depending on the complexity of the drawing.

Here I gave you some info, so you can relate. You didn’t provide any info, so it’s difficult to tell what’s wrong.

I have a class Project in the Globals module.
The form first gets a project: project = Project(project_number), then accesses its members. When it assigns the list of items to the repeating panel, the Project class does only one round trip to load everything. for example when the form does self.rep_pan.items = project.crates, the crates member of the class will do one server call and load everything needed to render all the crates for that project. The round trip is completed before the value is assigned to self.rep_pan.items.

At this point the repeating panel iterates through the crates and renders one by one. Each crate object already has all the info required for the rendering and I’m sure there are no other round trips.

I don’t think the write-back has anything to do with slow response times, unless the template form writes back during the rendering, but… why would it do that?

Unfortunately Anvil can sneakily perform round trips without telling you. I would like to know about it, but I can’t.

1 Like

Found the problem… It was unexpected… That was no overload of connections with server.

The problems was located at the top and GPU usage gave me hint. It was Lottie file… It was apparently for some reason eating way too many resources. Removing it solved the problem.

Judging from the questions I’ve seen here, Lottie isn’t a typical part of an Anvil app, so it didn’t occur to me to ask about third-party resources.

Benchmarking or profiling those is pretty much up to the user.

2 Likes

I have few of them and they are not causing such problems. This one used there was more complex. Apparently little to complex for weaker machines.

I changed some things based on your input to improve it anyway. Thank you