Page 1 of 1
AddGadgetItem very, very slow
Posted: Mon Nov 03, 2014 9:34 pm
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!
Re: AddGadgetItem very, very slow
Posted: Mon Nov 03, 2014 10:20 pm
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
Re: AddGadgetItem very, very slow
Posted: Mon Nov 03, 2014 10:29 pm
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

Re: AddGadgetItem very, very slow
Posted: Tue Nov 04, 2014 6:35 am
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")
Re: AddGadgetItem very, very slow
Posted: Tue Nov 04, 2014 7:13 am
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
Re: AddGadgetItem very, very slow
Posted: Tue Nov 04, 2014 8:13 am
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
Re: AddGadgetItem very, very slow
Posted: Tue Nov 04, 2014 8:35 am
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.
Re: AddGadgetItem very, very slow
Posted: Tue Nov 04, 2014 9:05 am
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.

Re: AddGadgetItem very, very slow
Posted: Tue Nov 04, 2014 11:11 am
by Lebostein
@wilbert & danilo
Thank you very much!!!

That's it!
@Fred: Would be nice to have a PB-Function for that....
Re: AddGadgetItem very, very slow
Posted: Tue Nov 04, 2014 2:44 pm
by IdeasVacuum
@Fred: Would be nice to have a PB-Function for that....
+1

Re: AddGadgetItem very, very slow
Posted: Tue Nov 04, 2014 10:01 pm
by Andre
@Fred: Would be nice to have a PB-Function for that....
+1
btw. - we are not in the Feature Requests forum here
Re: AddGadgetItem very, very slow
Posted: Wed Nov 05, 2014 8:29 pm
by davido
+1
Re: AddGadgetItem very, very slow
Posted: Fri Nov 07, 2014 3:25 am
by fsw
Danilo wrote:Damn, too late.

No, you are definitely not.
Your code is awesome
