Table widget slow in cocoa #2746
Replies: 2 comments 1 reply
-
(Converted into a discussion because it's still in the investigation stage, rather than a specific bug that can be resolved). Firstly - one really small optimisation - you shouldn't ever need to call I'm not able to reproduce a delay that is as bad as you're reporting. The fact that you're on macOS 10.15 and Python 3.9 suggests you've got an older x86-64 MacBook; if that's the case, that will be at least some of the cause of the delay you're seeing. You might see an improvement if you upgrade to Python 3.12 - recent Python versions have seen signficant speed boosts. However, I don't think that update alone will address the issue you're seeing. While I don't see a "1 second" delay, I do see a delay, for which I can think of two contributing causes. The first is that creating a visible row requires creating a number of Objective C objects, and that process takes time. I don't know if this matches your experience, but in my testing, once the visible table has been filled, adding rows that aren't visible seems a little faster. This is because the underlying macOS Table implementation is optimised so that it won't try to render rows that aren't visible - so they're created on demand when they become visible. Unfortunately, the fix for this is "make the Rubicon bridge faster" - and that isn't a trivial fix. Object creation is known to be slow because it involves some complex interactions between Python and Objective C; while there's possibly some ways that it could be sped up, those approaches require some fairly deep changes to Rubicon. The second cause is the nature of "bulk" updates like this. Adding 10 individual rows one at a time is not the same as adding 10 rows in one chunk; after adding each row, there are details about the entire table that need to be recomputed. When you insert 10 rows in rapid succession, there's a lot of duplicated (and ignored) effort. Toga doesn't currently have any "bulk update" APIs for list sources (e.g., So - what can you do in the meantime? Depending on your specific use case, you may find that it is faster to replace all the data, rather than add individual rows one at a time. Refreshing the entire table uses a different mechanism to inserting a row; depending on your specific use case, you might find that refreshing all the data is marginally faster:
Whether this helps will be very dependent on your specific use case. The other possibility is to provide better visual feedback of progress. As currently implemented, your
By making the method asynchronous, and awaiting a 0 second sleep, you give the button handler permission to hand control back to the GUI event loop, allowing the GUI to redraw. You should see rows being added at the speed they are created, rather than pausing until all the rows are ready. It's not a perfect solution, but it will at least providing visual feedback as fast as it can be provided, which might be enough for UX purposes. |
Beta Was this translation helpful? Give feedback.
-
freakboy3742, Many thanks for your feedback. I did some further testing:
As a work-around I have for the time being implemented pagination. I now only show one "page" of data in the table (~ 10 - 16 items) combined with page control (first/previous/next/last page buttons) below the table. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
Hi all,
I am porting a tkinter application to Toga so I can make use of Briefcase. So far I like Toga a lot (my code seems simpler and shorter than the tkinter code). I am experiencing issues with the performance of the Table widget in macos / cocoa however.
Please refer to the minimal code sample below. When pressing the button, 10 rows are added to a 20 col table. This operation takes one full second (button click ... rows appearing). With more rows, when scrolling the table, if frequently seems to "hang" for a short time. There are many situations where the one second update would not be an issue, but for the application in question (which modifies the table data frequently) it is. A workaround or fix allowing fast table updates would be great.
Otherwise my experience with the Table widget so far is quite good. What would be welcome however, next to fast data updates, is a way to set the height of the table in rows rather than pixels, and maybe a way to specify relative column widths. Also every cell in the table seems to always be editable, which I assume will be confusing to users if that is not intended by the application.
I might be missing something - first day with Toga - feel free to point out.
Steps to reproduce
Expected behavior
An almost immediate update, like in other gui toolkits.
Screenshots
No response
Environment
Logs
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions