Page 1 of 1

Datagrid slowness...

Posted: Thu Nov 15, 2012 12:15 pm
by paulsr
Greetings:

This is my first attempt at using a datagrid, so I have to assume I am doing something wrong.

I am reading a text file, and populating the first two columns of the grid. Here is the code:

Code: Select all

put empty into tGrid
   put 1 into tLnbr
   repeat while tLnbr <> 0
      read from file gLogFile for 1 line 
      put it into tLine          
      put the result into tRes
      if tRes = "" then
         put word 1 of tLine into tGrid[tLnbr]["Col 1"]
         put word 2 of tLine into tGrid[tLnbr]["Col 2"]
         add 1 to tLnbr 
      else 
         put 0 into tLnbr    
      end if
      set the dgData of grp "FldGrid" to tGrid

At this point the code is not intended to do anything really useful... I'm really just trying to learn how to use datagrids. But here's the problem...

With 100 records in the text file, the grid takes about 20 seconds to load on my Windows PC with Livecode 5.5.3. On my iPad1, it takes more than a minute. Surely this is not normal?

I read somewhere that using dgData is faster than dgText, but for me they seem to be about the same.

I also read that I shd check the Persistent Data box, but that makes no difference.

What am I missing here???

TIA

--paul

Re: Datagrid slowness...

Posted: Thu Nov 15, 2012 1:50 pm
by Klaus
Hi Pyul,

datagrids, especially of type TABLE, are fast, so I think it is more your script 8)

1. you set the DGDATA inside of your repeat loop!?
That will overwrite the data every time!
2. You read every line from file.
3. No idea what RESULT you are checking?

Try this:

Code: Select all

...
  put empty into tGrid
  
  ## Read the complete file into a variable, this will speed up thing very much!
  put url("file:" & gLogFile) into tFileContent
  put 1 into tLnbr
  repeat for each line tLine in tFileContent
    put word 1 of tLine into tGrid[tLnbr]["Col 1"]
    put word 2 of tLine into tGrid[tLnbr]["Col 2"]
    add 1 to tLnbr
  end repeat

  ## NOW set the data at once:
  set the dgData of grp "FldGrid" to tGrid
...
Best

Klaus

Re: Datagrid slowness...

Posted: Fri Nov 16, 2012 3:14 am
by paulsr
Klaus wrote: 1. you set the DGDATA inside of your repeat loop!?
That will overwrite the data every time!
Ahh, yes... that's the stupid mistake I hadn't spotted.
Klaus wrote:2. You read every line from file.
It didn't occur to me to do otherwise. Your solution is much nicer.
Klaus wrote:3. No idea what RESULT you are checking?
The US Presidential Election, I think!

Thanks Klaus, as always...

--paul

Re: Datagrid slowness...

Posted: Fri Nov 16, 2012 11:43 am
by Klaus
Hi Paul,
paulsr wrote:...
Klaus wrote:3. No idea what RESULT you are checking?
The US Presidential Election, I think!
:D
paulsr wrote:Thanks Klaus, as always...
--paul
You're welcome, as always :)


Best

Klaus