AddGadgetItem very, very slow
AddGadgetItem very, very slow
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!
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!
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: AddGadgetItem very, very slow
Can you add the items when the app is launched, before the Window is displayed?
Pseudo code:
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.
If it sounds simple, you have not grasped the complexity.
Re: AddGadgetItem very, very slow
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
For OS X 10.7 or higher, try if using beginUpdates / endUpdates makes a difference ...
Edit:
beginUpdates / endUpdates combined with a mutable index set also makes it possible to quickly select a lot of items.
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)
Raspberry Pi OS (Arm64)
Re: AddGadgetItem very, very slow
Damn, too late.
It makes a big difference:
Mac OS X: 1250ms vs. 50ms
Windows: 3958ms vs. 235ms
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
Mac OS X: 1250ms vs. 50ms
Windows: 3958ms vs. 235ms
Re: AddGadgetItem very, very slow
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.Danilo wrote:It makes a big difference:
Mac OS X: 1250ms vs. 50ms
Windows: 3958ms vs. 235ms
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.
Re: AddGadgetItem very, very slow
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
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
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.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.
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.
Yes, I get around 10% on Windows, didn't even tried on OS X.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
@wilbert & danilo
Thank you very much!!! That's it!
@Fred: Would be nice to have a PB-Function for that....
Thank you very much!!! That's it!
@Fred: Would be nice to have a PB-Function for that....
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: AddGadgetItem very, very slow
+1@Fred: Would be nice to have a PB-Function for that....
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
- Andre
- PureBasic Team
- Posts: 2071
- Joined: Fri Apr 25, 2003 6:14 pm
- Location: Germany (Saxony, Deutscheinsiedel)
- Contact:
Re: AddGadgetItem very, very slow
+1@Fred: Would be nice to have a PB-Function for that....
btw. - we are not in the Feature Requests forum here
Re: AddGadgetItem very, very slow
No, you are definitely not.Danilo wrote:Damn, too late.
Your code is awesome
I am to provide the public with beneficial shocks.
Alfred Hitshock