Hello,
after upgrading from Sierra to Mojave I noticed that an app of mine, created in Sierra, now takes about 10 secs before its opening process comes to an end.
The cause of this delay is that at opening time the app loads several popupmenus, each with about 300 rows.
So I created a new project with twelve popupmenus and the code below in a push button:
to load 300 rows, it takes about 210 ticks.
My MBP has got only 8G of memory, but in Sierra the delay was not as marked as now.
Using Xojo 2018r4, aggressive
Is there a way to speed up the process?
Sub Action() Handles Action
#pragma disableBackgroundTasks
#pragma disableBoundsChecking
dim tt as Double = Ticks
dim s as String = "wisdom"
for i as Integer = 0 to 300
for k as Integer = 0 to 11
PopupMenu1(k).AddRow s
//dim n as Integer = PopupMenu1(k).ListCount-1
//PopupMenu1(k).RowTag(n) = "some value"
next
next
for i as Integer = 0 to 11
PopupMenu1(i).ListIndex = 0
next
label1.text = Format(Ticks-tt, "#")
End Sub
No code anywhere. The 12 popupmenus do not have any event. The only code is in the push button populating the menus.
Unfortunately I do not have anymore Sierra, just to test and see how many ticks it would take to execute the same code.
personally… if I had the need for ONE popup with 300 items, I would want to rethink the GUI design. and with 12 such popups, that would be a definite rethink
Even with alphabetically populated data *, 300 items is a bit “too” many.
Remember: click in the PopupMenu followed by a L display the first word that start with L.
In a production software, and to avoid troubles (wrong dates), I have a PopupMenu with 100 (or was it 99 ?) entries (years since the current year): I am not happy with that at all, but it was the “best” I was thinking at (to avoid strange birth years…).
Despite the fact that I agree with the previous posters about the usability of such Popupmenus (have you considered using ComboBoxes with autocomplete, disallowing custom input?), the time you report is way too long.
Did you try to cache the current popup like
for k as Integer = 0 to 11
Dim CurrentPopup as PopupMenu = PopupMenu1(k)
for i as Integer = 0 to 300
CurrentPopup.AddRow s
next
CurrentPopup.ListIndex = 0
next
There are no problems loading 10,000s of rows, only the time it might take.
This example loads over 10,800 rows and needs around 6 seconds on a 2015 macBook Pro, but mostly because it does a lot of introspection while doing so:
There are not so many options, and you will have a hard time trying to reach the maximum row count. Anyway, all the options (PopupMenu, ComboBox, single-column ListBox) carry the necessity to create a DataSource (implicitly by addRow or similar methods), and the only means to speed this up are to either use native controls that have an open dataSource property (like ThomasÂ’ example of NSTableView with MBS controls) or to implement a cache/slize mechanism like in the DataOnDemandListbox.
While I agree that a popupmenu is not the best choice for 300 rows, and in fact I’m since then rethinking the approach to the problem, I wanted to point out that in Mojave popups are ways slower that, for instance, in Sierra.
Thank you for the advices and suggestions.
I ran into this same problem recently. ItÂ’s actually faster for me to build my selection popup menus on a web app in a remote location with a slow internet connection then on a native app. I donÂ’t have 300 items either, maybe half that. ItÂ’s perfectly reasonable in my mind to use popup menus for such a thing even with 300 or more items since you can type ahead to find the thing youÂ’re looking for as long as they are added alphabetically.
There is a HUGE difference in speed for adding rows to a popup menu on Mojave as opposed to everything that has gone before youÂ’re absolutely correct. Any discussion about if this is the right thing to do or not is not helpful as there is a definite bug in either xojo or the OS regarding this.
I have built myself a type ahead something like the combobox as I couldnÂ’t get that to do what I wanted. But there is definitely something wrong with adding rows to popup menus in mojave, itÂ’s orders of magnitude slower. The window I had with 5 popups with around 200 entries in them opens in an eyeblink on previous OSÂ’s and takes upwards of 7 seconds on Mojave.
I already refactored the interface of my app, getting rid of the popupmenus. But I agree with you that correctly or uncorrectly using popups is not the crux of the matter; the crux of the matter being that in Mojave they have become slow.