Debug performance hiccups #4888
Replies: 7 comments 3 replies
-
Issues like this are typically caused by blocking operations. I would suspect anything that does IO, processes, or networking. The solution is usually to do that work concurrently (in a Textual worker). Alternatively, look for anything that might be cpu intensive. And do that in a threaded worker. You might want to use PyInstrument, which is a very simple Python profiler. It may indicate where your app is spending an excessive amount of time. |
Beta Was this translation helpful? Give feedback.
-
That was my thought as well, but there really isnt any of my code involved in the scenario causing the issue - Simply scrolling through a datatable. No background work or anything running either, afaik. Profiler isnt super helpful because it's a small amount of wall-clock time where the app is unresponsive and since it's a repetitive action that elicits the issue (key-down on datatables), the stack frames for fast + slow periods look the same / timing information just accumulates under those frames Is there any way to log individual events which take >x seconds to be queued+processed, or any way to generally debug sizable message queues across all components in the app? |
Beta Was this translation helpful? Give feedback.
-
You can see events being processed with the dev tools. That might give you a clue. |
Beta Was this translation helpful? Give feedback.
-
Added some additional logging to the dev console, incl microsecond-precise timestamps instead of seconds. I observe a delay during the bubbling of an event up the stack: In this example, I see the key down events fire, which are handled/turned into Once the Not sure exactly where I'll proceed next, but figured I'd post here in case anyone has ideas |
Beta Was this translation helpful? Give feedback.
-
Interestingly as well, I've noticed that the problem is recreatable even when not holding the |
Beta Was this translation helpful? Give feedback.
-
Added more logging, the pauses seem to align with fires of In particular, it seems that the latency is introduced by the call to |
Beta Was this translation helpful? Give feedback.
-
Okay! Found the source - Py interpreter GC'ing... Correlates with those compositor refreshes as it seems those allocate a bunch of temporary objects. Confirmed by calling @willmcgugan Do you think the garbage collector could be disabled by Textual and instead manually invoked in |
Beta Was this translation helpful? Give feedback.
-
Is there a recommended way to debug specific events with unusually high latency? I typically use profilers like
Austin
, but the issue I'm experiencing is sporadic and is difficult to track down when profiling the application as a whole.The issue I'm looking to debug is a performance hiccup when scrolling thru large datatables. If I press/hold the down-arrow, the table will scroll smoothly for ~5lines, then pause for a few seconds, then continue scrolling, repeating the hiccup every ~5 lines or so. I'd like to track down why those key-down events arent being processed in a timely manner to keep the UI responsive
Beta Was this translation helpful? Give feedback.
All reactions