AddGadgetItem very, very slow

Mac OSX specific forum
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

AddGadgetItem very, very slow

Post by Lebostein »

Hi,

is it possible to speed up AddGadgetItem + ListIconGadget? I can speed up the Windows version by hiding the gadget (I think there is no refresh procedure with that way):

HideGadget(#G, #True)
AddGadgetItem's
HideGadget(#G, #False)

But with Mac OS this don't work... only 1000 items needs more than a second to add!
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: AddGadgetItem very, very slow

Post by IdeasVacuum »

Can you add the items when the app is launched, before the Window is displayed?
Pseudo code:

Code: Select all

OpenWindow(#Win, x, y, w, h, MyWin, #PB_Window_Invisible)
         ListIcon()
         Repeat
                        AddItem()
                        item+
         Until item = 1000
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: AddGadgetItem very, very slow

Post by Lebostein »

I have lists with more than 10000 entries, I add and remove items in realtime by typing words/phrases in a search field (filtering entries). With Windows (and the workaround above) it works very well. But with Mac OS it is a horror :|
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: AddGadgetItem very, very slow

Post by wilbert »

For OS X 10.7 or higher, try if using beginUpdates / endUpdates makes a difference ...

Code: Select all

CocoaMessage(0, GadgetID(MyListIconGadget), "beginUpdates")
For i = 1 To 1000
 AddItem()
Next
CocoaMessage(0, GadgetID(MyListIconGadget), "endUpdates")

Edit:
beginUpdates / endUpdates combined with a mutable index set also makes it possible to quickly select a lot of items.

Code: Select all

EnableExplicit
DisableDebugger

Define.i ListIconGadgetID, IndexSet, i

OpenWindow(0, 0, 0, 500, 300, "ListIcon Example")
ListIconGadget(0, 10, 10, 480, 220, "Line number", 470)
ButtonGadget(1, 10, 250, 100, 25, "Select")
For i = 0 To 99999
  AddGadgetItem(0, -1, "Line " + Str(i))
Next

ListIconGadgetID = GadgetID(0)
IndexSet = CocoaMessage(0, 0, "NSMutableIndexSet new")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 1
        CocoaMessage(0, IndexSet, "removeAllIndexes")
        For i = 0 To 99999 Step 2
          CocoaMessage(0, IndexSet, "addIndex:", i)
        Next
        CocoaMessage(0, ListIconGadgetID, "beginUpdates")
        ; byExtendingSelection: YES     => Extend current selection
        ; byExtendingSelection: NO      => Replace current selection
        CocoaMessage(0, ListIconGadgetID, "selectRowIndexes:", IndexSet, "byExtendingSelection:", #NO)
        CocoaMessage(0, ListIconGadgetID, "endUpdates")
      EndIf
   EndSelect
ForEver

CocoaMessage(0, IndexSet, "release")
Last edited by wilbert on Wed Nov 09, 2022 7:40 pm, edited 1 time in total.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: AddGadgetItem very, very slow

Post by Danilo »

Damn, too late. :)

Code: Select all

Procedure BeginListIconUpdate(listIconGadget)
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
        SendMessage_(GadgetID(listIconGadget),#WM_SETREDRAW,0,0)
    CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS
        CocoaMessage(0,GadgetID(listIconGadget),"beginUpdates")
    CompilerEndIf
EndProcedure

Procedure EndListIconUpdate(listIconGadget)
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
        SendMessage_(GadgetID(listIconGadget),#WM_SETREDRAW,1,0)
        InvalidateRect_(GadgetID(listIconGadget),0,1)
        UpdateWindow_(GadgetID(listIconGadget))
    CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS
        CocoaMessage(0,GadgetID(listIconGadget),"endUpdates")
    CompilerEndIf
EndProcedure

OpenWindow(0,0,0,800,600,"ListIconGadget",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ListIconGadget(0, 10, 10, 780, 580, "Name", 110)
AddGadgetColumn(0, 1, "Address", 200)

While WindowEvent():Wend


startTime = ElapsedMilliseconds()
    BeginListIconUpdate(0)
        For i = 1 To 10000
            AddGadgetItem(0, -1, "Name " + Str(i) + #LF$ + "Address " + Str(i))
        Next
    EndListIconUpdate(0)
endTime = ElapsedMilliseconds()-startTime


SetWindowTitle(0,"ListIconGadget - Time: "+Str(endTime)+" ms")    
    
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
It makes a big difference:
Mac OS X: 1250ms vs. 50ms
Windows: 3958ms vs. 235ms
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: AddGadgetItem very, very slow

Post by bbanelli »

Danilo wrote:It makes a big difference:
Mac OS X: 1250ms vs. 50ms
Windows: 3958ms vs. 235ms
Interesting results. In my case, the largest difference I get is with Windows. There seems to be no issues on Linux with adding items to gadget. What CPU are you using? Mine on development machine is i5-4440.

Windows: 1024 ms vs. 110ms
OS X: 120 ms vs. 42ms
Linux: 88ms
Last edited by bbanelli on Tue Nov 04, 2014 8:39 am, edited 1 time in total.
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: AddGadgetItem very, very slow

Post by Danilo »

bbanelli wrote:What CPU are you using?

Code: Select all

; Mac Mini Server (late 2012)
; Mac OS X 10.10 (Yosemite)
; 2.6 GHz quad-core Intel Core i7 (i7-3720QM Turbo Boost up to 3.6 GHz)
; Cache: 6 MB L3
; 16 GB 1600 MHz DDR3

Code: Select all

; Self-build PC, 5+ years old
; Windows 8.1 Enterprise
; 2.66 GHz Intel Core2 Quad Q9450
; 8 GB 800 MHz DDR2
BTW: I did not want to compare Windows vs. Mac OS X speed here. I wanted to show the speed-up with BeginListIconUpdate() vs. not using it. ;)
Also, quick tests were made with PB x86. Using the 64bit compiler, all results are round about 15% to 20% faster, on Windows and Mac OS X.
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: AddGadgetItem very, very slow

Post by bbanelli »

Danilo wrote:BTW: I did not want to compare Windows vs. Mac OS X speed here. I wanted to show the speed-up with BeginListIconUpdate() vs. not using it. ;)
Sure thing, I'm completely aware of that, but we have basically same CPU, at least concerning speed of adding items to the gadget, and it takes 20 times more time to populate list than it takes me on Virtual machine, where it takes twice more, but still negligible in user experience.

Even better, running same example (well, executable file, to tell the truth) on Sempron 145 (Windows 7) i get ~1900ms vs. 200ms which is still lower than your example and you have significantly faster CPU.

Those are a bit awkward results, nothing more. :)
Also, quick tests were made with PB x86. Using the 64bit compiler, all results are round about 15% to 20% faster, on Windows and Mac OS X.
Yes, I get around 10% on Windows, didn't even tried on OS X. :)
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: AddGadgetItem very, very slow

Post by Lebostein »

@wilbert & danilo
Thank you very much!!! :lol: That's it!

@Fred: Would be nice to have a PB-Function for that....
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: AddGadgetItem very, very slow

Post by IdeasVacuum »

@Fred: Would be nice to have a PB-Function for that....
+1 :mrgreen:
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2071
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: AddGadgetItem very, very slow

Post by Andre »

@Fred: Would be nice to have a PB-Function for that....
+1

btw. - we are not in the Feature Requests forum here
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: AddGadgetItem very, very slow

Post by davido »

+1
DE AA EB
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: AddGadgetItem very, very slow

Post by fsw »

Danilo wrote:Damn, too late. :)
No, you are definitely not.
Your code is awesome :!:

I am to provide the public with beneficial shocks.
Alfred Hitshock
Post Reply