Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Loading items into a listview -- performance issue.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Mon Mar 06, 2017 12:23 am    Post subject: Loading items into a listview -- performance issue. Reply with quote

I am using the following function to load data into a listview (I copied it from a post on this forum):
Code:

function addLevelItem(control, level, one, two, three, four, five , six, seven)
  local lvitems=listview_getItems(control)
  local item=listitems_add(lvitems)
  local subitems=listitem_getSubItems(item)

  listitem_setCaption(item,level)
  strings_add(subitems, one)
  strings_add(subitems, two)
  strings_add(subitems, three)
  strings_add(subitems, four)
  strings_add(subitems, five)
  strings_add(subitems, six)
  strings_add(subitems, seven)
end

function LoadDate()
   for i=1,200 do
        .....  <-----get data from memory
        addLevelItem(......)   <-------------use the function to add data into listview
   end
end


The problem is the lack of performance(speed). The trainer lagged a bit even when I was only loading less than 200 entries. Is there a way to speed it up? What is the cause of the lag, is it because that I get items from control in every loop?

Thanks.

_________________
**************

A simple example is better then ten links. Very Happy
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Mon Mar 06, 2017 2:03 am    Post subject: Reply with quote

Make use of the beginUpdate/endUpdate calls before and after you start adding items to the ListView to prevent it from redrawing each item that is inserted until you are finished. Should speed things up.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Mon Mar 06, 2017 10:56 am    Post subject: Reply with quote

atom0s wrote:
Make use of the beginUpdate/endUpdate calls before and after you start adding items to the ListView to prevent it from redrawing each item that is inserted until you are finished. Should speed things up.


Thanks for the reply. Do you mean this?
Code:

function addLevelItem(control, level, one, two, three, four, five , six, seven)
  local lvitems=listview_getItems(control)
  local item=listitems_add(lvitems)
  local subitems=listitem_getSubItems(item)

  listitem_setCaption(item,level)
  beginUpdate()  <-----------------------begin here?
  strings_add(subitems, one)
  strings_add(subitems, two)
  strings_add(subitems, three)
  strings_add(subitems, four)
  strings_add(subitems, five)
  strings_add(subitems, six)
  strings_add(subitems, seven)
  stopUpdate()  <---------------------- stop here?
end


Or do you mean to use them before the loop and after the loop?

_________________
**************

A simple example is better then ten links. Very Happy
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Mon Mar 06, 2017 11:04 am    Post subject: Reply with quote

before and after the loop

e.g before calling the loop that calls addLevelItem call control.beginUpdate() and after the loop call control.endUpdate()


example:
Code:

function addLevelItem(control, level, one, two, three, four, five , six, seven)
  local item=control.add()
  item.caption=level
  item.subitems.add(one)
  item.subitems.add(two)
  item.subitems.add(three)
  item.subitems.add(four)
  item.subitems.add(five)
  item.subitems.add(six)
  item.subitems.add(seven)
end


UDF1.ListView1.beginUpdate()
for i=1,200 do
  addLevelItem(UDF1.Listview,'aaa','bbb','ccc','ddd','eee','fff','ggg','hhh')
end
UDF1.ListView1.endUpdate()


Alternatively, if it is a REALLY big amount of data, try OwnerData=true and then set ListView.Items.Count to the amount of items there are, and give it an OnData event where you fill in the entry based on the index it's at

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Mon Mar 06, 2017 11:19 am    Post subject: Reply with quote

Dark Byte wrote:
before and after the loop

e.g before calling the loop that calls addLevelItem call control.beginUpdate() and after the loop call control.endUpdate()


example:
Code:

function addLevelItem(control, level, one, two, three, four, five , six, seven)
  local item=control.add()
  item.caption=level
  item.subitems.add(one)
  item.subitems.add(two)
  item.subitems.add(three)
  item.subitems.add(four)
  item.subitems.add(five)
  item.subitems.add(six)
  item.subitems.add(seven)
end


UDF1.ListView1.beginUpdate()
for i=1,200 do
  addLevelItem(UDF1.Listview,'aaa','bbb','ccc','ddd','eee','fff','ggg','hhh')
end
UDF1.ListView1.endUpdate()


Alternatively, if it is a REALLY big amount of data, try OwnerData=true and then set ListView.Items.Count to the amount of items there are, and give it an OnData event where you fill in the entry based on the index it's at


Thanks for the reply. However, there are some issues in your example.

1. The addLevelItem() function returns this error message: attempt to call a nil value (field 'add').

2. So I had to use my old addlevelItem() function, and then I put beginUpdate() and endUpdate() before and after the loop as you instructed. However, the listview is empty after all the execution. No columns no nothing. Sad Did I do something wrong?

_________________
**************

A simple example is better then ten links. Very Happy
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Mon Mar 06, 2017 12:03 pm    Post subject: Reply with quote

You need to initialize the columns:
Code:

...
  while control.Columns.Count<= 7 do control.Columns.add().Caption = control.Columns.Count end

 listitem_setCaption(item,level)


Columns 0 is for listitem, Columns 1-7 is for listitem's subitems. (Count will be 8 in above example)

_________________
- Retarded.
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Mon Mar 06, 2017 12:49 pm    Post subject: Reply with quote

panraven wrote:
You need to initialize the columns:
Code:

...
  while control.Columns.Count<= 7 do control.Columns.add().Caption = control.Columns.Count end

 listitem_setCaption(item,level)


Columns 0 is for listitem, Columns 1-7 is for listitem's subitems. (Count will be 8 in above example)


Thanks, panraven. But I still can't make begin and end update work. Sad

_________________
**************

A simple example is better then ten links. Very Happy
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Mon Mar 06, 2017 2:49 pm    Post subject: Reply with quote

Try replace DB's code <<UDF1.ListView1>> in your 'control', the columns should init outside the loop too.
May also set your control's Align to alClient, so that it fill your form.
Code:

local myListView = <<your-control>>
myListView.Align = alClient

 while myListView.Columns.Count<= 7 do myListView.Columns.add().Caption = myListView.Columns.Count end

myListView.beginUpdate()
for i=1,200 do
  addLevelItem(myListView,'aaa','bbb','ccc','ddd','eee','fff','ggg','hhh')
end
myListView.endUpdate()


The beginUpdate/endUpdate may only exist in a recent ce version (6.6?).

_________________
- Retarded.
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Mon Mar 06, 2017 5:16 pm    Post subject: Reply with quote

panraven wrote:
Try replace DB's code <<UDF1.ListView1>> in your 'control', the columns should init outside the loop too.
May also set your control's Align to alClient, so that it fill your form.
Code:

local myListView = <<your-control>>
myListView.Align = alClient

 while myListView.Columns.Count<= 7 do myListView.Columns.add().Caption = myListView.Columns.Count end

myListView.beginUpdate()
for i=1,200 do
  addLevelItem(myListView,'aaa','bbb','ccc','ddd','eee','fff','ggg','hhh')
end
myListView.endUpdate()


The beginUpdate/endUpdate may only exist in a recent ce version (6.6?).


Thanks, I did replace the listview variable in DB's example, but I did not set the Align property. I will give it a try when I get home. Smile

_________________
**************

A simple example is better then ten links. Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites