Re: MacOS Tahoe painfully slow a wxChoice containing 6k entries.

Tony Kennedy <[email protected]> Wed, 10 Dec 2025 03:09:41 -0800 (PST)
Newsgroups gmane.comp.lib.wxwindows.general
Message-ID <[email protected]>
Another update as I should have tested these out before posting.

"Solution 1" does not work, it's still slow.





On Wednesday, 10 December 2025 at 10:41:54 UTC Tony Kennedy wrote:

> Sadly it's not going to be as simple as solution 2 above as any 
> "Bind(wxEVT_CHOICE" on the control will need reworking.
>
>
> On Wednesday, 10 December 2025 at 10:12:33 UTC Tony Kennedy wrote:
>
>> An update as this potentially impacts all MacOS controls that have a 
>> NSMenu internally.
>>
>> I had a feeling it was "Spotlight" that was the problem based on 
>> https://discussions.apple.com/thread/256145409?sortBy=rank.
>>
>> Using chatgpt (I'm not familiar with Apple and Spotlight which seems to 
>> be the cause of the problem), it gave me a workaround.
>>
>> From chatgpt,
>> On macOS, wxChoice is implemented using a *native NSPopUpButton*, which 
>> internally creates an *NSMenu* with 6000 NSMenuItems. macOS 
>> Spotlight/Accessibility *automatically scans every NSMenuItem* for 
>> metadata every time the menu changes — especially when
>>
>>    - 
>>    
>>    clearing all items
>>    - 
>>    
>>    recreating items
>>    - 
>>    
>>    calling Clear()
>>    - 
>>    
>>    calling Append() thousands of times
>>    
>> This is why your app hangs for *60+ seconds*.
>>
>>
>> Two solutions.
>>
>> 1. Don't use "Clear", instead create a wxArrayString object, add all the 
>> strings and then call pChoice->Set(items);
>>
>>
>> 2. Replace wxChoice with wxOwnerDrawnComboBox.
>> #if defined(__WXMAC__)
>>     #define WX_CHOICE wxOwnerDrawnComboBox
>>     #define WX_CHOICE_FLAGS(parent, id, value, pos, size, choices, style) 
>> \
>>         wxOwnerDrawnComboBox(parent, id, value, pos, size, choices, style)
>> #else
>>     #define WX_CHOICE wxChoice
>>     #define WX_CHOICE_FLAGS(parent, id, value, pos, size, choices, style) 
>> \
>>         wxChoice(parent, id, value, pos, size, choices, style)
>> #endif
>>
>> and then replace
>>
>> wxChoice* myChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, 
>> wxDefaultSize, items);
>>
>> with
>>
>> WX_CHOICE* myChoice = WX_CHOICE_FLAGS(this, wxID_ANY, wxEmptyString,
>>                                       wxDefaultPosition, wxDefaultSize,
>>                                       items, 0);
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On Wednesday, 10 December 2025 at 09:31:15 UTC Tony Kennedy wrote:
>>
>>> Hi all,
>>>
>>> Using MacOS Tahoe and wx 3.3.0.0.
>>>
>>> A user has reported that there is a crazy slowdown when using MacOS 
>>> Tahoe.
>>>
>>> The offending line in my code is 
>>>
>>> m_pChoice->Clear();
>>>
>>> The wxChoice control has 6500 entries and takes approximately a minute 
>>> to clear all entries.
>>>
>>> Has anyone else experienced something similar?
>>>
>>> All is fine on both Windows and other versions of MacOS. And previous 
>>> versions of my app that used earlier wx (3.2.6) is also fine.
>>>
>>> Any advice would be very welcome.
>>>
>>> Thanks in advance,
>>>
>>> Tony.
>>>
>>>

-- 
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
--- 
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/wx-users/eb459773-8bf6-452d-85c9-116f19e13ae1n%40googlegroups.com.