PyQt Application Optimization

For those of you who have written quite complex PyQt applications, what tips and tricks do you offer to speed up your applications? I have some examples of where my program starts to slow down as it grows:

  • I have a โ€œpanelโ€ written that is destroyed and recreated when the user clicks on an item in a TreeWidget. What would be the best way to have a modular interface when clicking an element in a TreeWidget changes the control panel, but does not require the widget to be destroyed and recreated.

  • Each panel also downloads an image from a network location. This leads to some slowdown, as one moves around the application, but after loading it into memory, "return to the same dash" is faster. Is there a good way or way to start a thread when loading a program that can preload images into memory? If so, how do you implement this?

  • When you have a large number of dashboard elements and data that is loaded into them, do you guys usually load the data and load it back into which each thread terminates? Is it viable when someone browses quickly? Will a kill-switch be implemented for threads in such a way that when a user changes the dashboards, threads work? Or the constant creation and killing of threads will cause some kind of, well, crisis.

Sorry for the sheer number of questions, but they seemed similar enough to guarantee that they came together.

+6
source share
2 answers

I'm not sure if this is exactly the same as what you are doing, but it looks like what I have in some applications where there is a list of custom widgets. And it slows down significantly when you create and destroy tons of widgets.

If the problem is with fewer common widgets, but just created and deleted a lot, you can just create widgets once and change the data of these widgets only as the information is updated ... as opposed to creating new widgets every time the information changes. That way, you can even change data from streams without worrying about creating widgets.

Another situation is where you display a list with custom widgets, and there are TON results. I notice that it always slows down when you have 1000 custom widgets in the list. The trick my colleague came across was to have a fake list where it uses the static number of slots on the display. Let's say it shows 10 slots in a view. The scrollbar does not actually scroll down through the MORE widget ... what it does is scroll DATA through 10 visible widgets. You can achieve insane performance gains. But only if this is an acceptable display style for your application.

+7
source

Do you use QNetworkAccessManager to upload images? It supports cache. It also loads everything in the background with the completion of callbacks.

I do not understand what your panel does. Are you thinking about using QWebkit? Maybe your toolbar content is easy to implement in HTML?

PS. I don't like threads in Python and I don't think this is a good idea. Pending jobs delegated to the Qt core are better.

+1
source

Source: https://habr.com/ru/post/893175/


All Articles