Virtual ListView 10000 rows, high CPU time Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Virtual ListView 10000 rows, high CPU time

Post by SKAN » 15 Jan 2022, 16:59

I am writing a Win32 constants picker for my Always-running-script.
If I search for IID_ I get like 7500+ matching results. Can't wait for them all to load in a ListView.
I need instant results.

I thought I could use a Virtual listview, but scrolling is so cpu intensive.
Try scrolling through all 10000 rows with process visible in task manager. You can watch the CPU time grow.
My Always-running-script hardly clocks 1 sec after a full day use. Can''t really use this..

Can some improvement be done for less CPU usage?
Adapted from @just me's demo posted @ autohotkey.com/r?p=25486
 
image.png
image.png (14.35 KiB) Viewed 2252 times
 

Code: Select all

; Adapted from just me's demo posted @ autohotkey.com/r?p=25486
; Simplified demo of Virtual ListView (10000 rows). By SKAN

#Requires AutoHotkey v2.0-
#Warn
#SingleInstance

VarSetStrCapacity(&Str,260)
pStr  :=  StrPtr(Str)

MyGui := Gui(,"Virtual ListView")

; +0x1140     : LVS_OWNERDATA (0x1000) | LVS_AUTOARRANGE (0x0100) | LVS_SHAREIMAGELISTS (0x0040)
MyLV := MyGui.Add("ListView", "Grid xm r16 w432 +0x1140 -Hdr +LV0x014000", ["",""])
MyLV.ModifyCol(1, "200")
MyLV.ModifyCol(2, "200")
MyGui.Show()

MyLV.OnNotify(0xFFFFFFFFFFFFFF4F, GetDisplayInfo)     ; LVN_GETDISPINFO
SendMessage(0x0000102F, 10000, 0x00000001, MyLV.Hwnd) ; LVM_SETITEMCOUNT, cItems, LVSICF_NOINVALIDATEALL

GetDisplayInfo(GuiControl, lParam) ; LVN_GETDISPINFO
{
    Global Str, pStr
    Local  szNMHDR   :=  A_PtrSize * 3
         , pLVITEMW  :=  lParam + szNMHDR
         , mask      :=  NumGet(pLVITEMW,  0, "uint")
         , iItem     :=  NumGet(pLVITEMW,  4, "int")
         , iSubItem  :=  NumGet(pLVITEMW,  8, "int")

        If mask & 1 ; LVIF_TEXT 1
           Str := Format("Row: {1:}   Column: {2:}", iItem, iSubItem)
        ,  NumPut("ptr", pStr, pLVITEMW,  20 + (A_PtrSize=8?4:0)) ; pszText
}
Last edited by SKAN on 16 Jan 2022, 12:57, edited 1 time in total.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Virtual ListView 10000 rows, high CPU time

Post by swagfag » 16 Jan 2022, 05:31

maybe u can batch load/unload listviewitems in chunks of 100 and employ some SetScrollInfo trickery to prevent the scrollbars from jumping all over the place as u load/unload items when reaching certain scroll thresholds
even so, a 100-item listview u can still get up to 10% cpu usage by scrolling very... vigorously

or maybe u can find some other lv implementation on the internet better optimized for many items
or maybe u can write ur own custom lv control based on Direct2D so the rendering can be hardware accelerated, but that seems like way too much work

neogna2
Posts: 590
Joined: 15 Sep 2016, 15:44

Re: Virtual ListView 10000 rows, high CPU time

Post by neogna2 » 16 Jan 2022, 05:33

Scrolling a lot in the example uses up 10% of CPU resources on my PC. I don't know how to lessen that.

With that much data I prefer to make a searchbox for filter-as-you-type against the whole data set and a smaller listview with e.g. 20 rows of results. That way you only need to update and redraw the 20 rows on each new typed character, which is usually very fast.

User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Virtual ListView 10000 rows, high CPU time

Post by SKAN » 16 Jan 2022, 06:29

swagfag wrote:
16 Jan 2022, 05:31
maybe u can batch load/unload listviewitems in chunks of 100 and employ some SetScrollInfo trickery to prevent the scrollbars from jumping all over the place as u load/unload items when reaching certain scroll thresholds
No DllCall()'s for this project. I either use it heavily or totally avoid it...
Currently I'm using an updown control to list data and manipulate it when WM_MOUSEWHEEL and LVN_KEYDOWN messages are recvd by listview control.
Absolutely no strain to CPU.. but listview flickers on fast updation. LV options -redraw/+redraw doesn't seem to help.
Also, Listview looks weird without a scroll-bar. A user wouldn't know to use mouse-wheel when a scroll bar isn't present.
 
image.png
image.png (19.41 KiB) Viewed 2173 times
 
neogna2 wrote:
16 Jan 2022, 05:33
I prefer to make a searchbox for filter-as-you-type against the whole data set and a smaller listview with e.g. 20 rows of results. That way you only need to update and redraw the 20 rows on each new typed character, which is usually very fast.
 
That is what I am currently doing. Result is 7,576 against the original count of 152,039.
User needs to have access to all 7,576 results.

just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Virtual ListView 10000 rows, high CPU time  Topic is solved

Post by just me » 16 Jan 2022, 08:33

On my system (Core i3-2310M @ 2.1 GHz) it needs 170 - 250 ms to (re)fill a list-view with 7000 to 10000 items. That's ok for me. Excessive scrolling in this list-view uses up to 20% CPU too.

Code: Select all

#Requires AutoHotkey v2.0-
#Warn
#SingleInstance

MyGui := Gui( ,"ListView")
MyLV := MyGui.Add("ListView", "Grid xm r16 w432 -Hdr +LV0x014000", ["",""])
MyLV.ModifyCol(1, "200")
MyLV.ModifyCol(2, "200")
MyBtn := MyGui.AddButton("xm w200", "Fill LV")
MyBtn.OnEvent("Click", BtnClick)
MyGui.Show()

BtnClick(Btn, Info) {
   S := A_TickCount
   I := Random(7000, 10000)
   Fill_LV(MyLV, I)
   T := A_TickCount - S
   MsgBox(T . " ms for " . I . " rows", A_ThisFunc, 0)
}

Fill_LV(LV, Items) {
   LV.Opt("-Redraw")
   LV.Delete()
   SendMessage(0x102F, Items, 0x00000000, LV) ; makes no difference
   Loop Items
      LV.Add("", "Row: " . A_Index . " of " . Items . " Column: 1", "Row: " . A_Index . " Column: 2")
   LV.Opt("+Redraw")
}

User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Virtual ListView 10000 rows, high CPU time

Post by kczx3 » 16 Jan 2022, 09:47

I'm still not clearing on the problem exactly. Sure, it spikes the CPU (never went above 10% for me) but it works great imho. The CPU drops back down when done scrolling. You think a C# or C++ app wouldn't experience the same thing?

User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Virtual ListView 10000 rows, high CPU time

Post by SKAN » 16 Jan 2022, 10:43

just me wrote:
16 Jan 2022, 08:33
Excessive scrolling in this list-view uses up to 20% CPU too.
 
Yes. Definitely more than the virtual listview.
I will go for it.
I will mark your post as answer.
Thanks.

:thumbup:

User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Virtual ListView 10000 rows, high CPU time

Post by SKAN » 16 Jan 2022, 10:58

kczx3 wrote:
16 Jan 2022, 09:47
You think a C# or C++ app wouldn't experience the same thing?
 
Try everything. It uses a regular SysListView32
 
image.png
image.png (17.42 KiB) Viewed 2093 times
 
1223997 rows.. Scrolling doesn't do a thing to the CPU.
 

To everybody:
You can't measure a thing by seeing a CPU spike. There is a "CPU time" column (needs to be enabled) in Details tabs.
Just 6 times top-bottom-top scroll uses 6 seconds of CPU. if I took 6 secs to complete my scrolling.. then thats 100% cpu core usage....
 
image.png
image.png (21.01 KiB) Viewed 2093 times

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Virtual ListView 10000 rows, high CPU time

Post by swagfag » 16 Jan 2022, 11:50

image.png
image.png (9.14 KiB) Viewed 2076 times
so much for not doing a thing to the CPU. its even worse than the ahk script lol

User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Virtual ListView 10000 rows, high CPU time

Post by SKAN » 16 Jan 2022, 12:01

swagfag wrote:
16 Jan 2022, 11:50
image.png
Seems I didn't test properly.
What app is that?

Edit:
I see now there is 2 process and I was seeing the wrong one. My bad.

@swagfag I don't appreciate the attitude you show when replying to me. :thumbdown:

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Virtual ListView 10000 rows, high CPU time

Post by swagfag » 16 Jan 2022, 12:49

ProcessHacker/procmon, either will do
SKAN wrote:
16 Jan 2022, 12:01
@swagfag I don't appreciate the attitude you show when replying to me. :thumbdown:
what attitude? nowhere in these posts am i even referring to u. one is a straight up answer and the other is commenting on the app

User avatar
oldbrother
Posts: 273
Joined: 23 Oct 2013, 05:08

Re: Virtual ListView 10000 rows, high CPU time

Post by oldbrother » 01 Jan 2023, 18:56

Hi SKAN, Can you please make a V1 version of your virtual listview example code? Is it possible to use it to load a large CSV file?

Happy New Year to you all!

Post Reply

Return to “Ask for Help (v2)”