Forum: Ruby-Gnome 2 help with liststore

2aa32559134aa3d596fb749f8ffccde7?d=identicon&s=25 hendra kusuma (Guest)
on 2011-03-28 17:54
(Received via mailing list)
Dear all,

I need to display a lot of data in treeview,
for the time being it's about 5000 rows with 20 columns
it will grow,

I use gtk liststore, append and set_value each data
but it runs very slow, and I mean Very Very Slow

Is there a better way?
8616a8bf5c9ac0db67ac26f89d3b06b6?d=identicon&s=25 Mike Charlton (Guest)
on 2011-03-29 04:24
(Received via mailing list)
On 29 March 2011 00:46, hendra kusuma <penguinroad@gmail.com> wrote:
> I use gtk liststore, append and set_value each data
> but it runs very slow, and I mean Very Very Slow

Yes, creating the list store is very, very slow.  I haven't
found a better way to do it unfortunately (although for my
app large lists are rare, so I haven't looked into it fully).
I'll give you a few general pointers on optimizing ruby-gtk
apps, though.

Generally speaking, you should avoid creating objects.  1.9.x
may be better in this respect, but at least with 1.8.x I have
found that simply making objects is a bottle neck.
Each object has an overhead (800 bytes???  I can't remember)
and the amount of memory it takes is huge.  Once you get
up in the 100,000 object range managing the memory and
garbage collection can eat CPU on smaller machines.

With large datasets as much as possible I try to use
arrays of strings (overhead of a string seems to be less
than a usual object) and then parse the string when I need
to use it.  So instead of having an array of objects each with
their field as your liststore, you can have an array of strings,
parse it when you are creating the fields you want to
display and again when you select an object.  It seems
like it would be slower, but it has given me some improvement
on my app.

The other thing you should do is avoid things like each().
For whatever reason, each() is very slow in Ruby.  As
much as possible try to use methods where the loop
is written in C code rather than Ruby code.  For example,
try to use collect() with a block.  Things like any?() and
all?() are significantly faster than setting up your own loop.

Anyway, the best thing to do is to profile your app
and check what is actually eating the time.  Think of
different ways to do the same thing.  Various ruby calls
have very different performance characteristics, so
keep trying to do things in different ways to see which
one is faster.  (This is of course after you make sure that
your algorithms are computationally as simple as possible).

        Hope that helps,
              MikeC
2aa32559134aa3d596fb749f8ffccde7?d=identicon&s=25 hendra kusuma (Guest)
on 2011-03-29 06:48
(Received via mailing list)
On Tue, Mar 29, 2011 at 10:23 AM, Mike Charlton <mikekchar@gmail.com>
wrote:

> Generally speaking, you should avoid creating objects.  1.9.x
> to use it.  So instead of having an array of objects each with
> try to use collect() with a block.  Things like any?() and
>        Hope that helps,
>              MikeC
>

Very helpful
not that I find a solution, but at least I know the problem.
from what I found, what slowing down is ruby, not gtk lib
I guess I need to throw some trial and error a little bit

btw, I have zero knowledge of C.
2aa32559134aa3d596fb749f8ffccde7?d=identicon&s=25 hendra kusuma (Guest)
on 2011-03-29 09:32
(Received via mailing list)
On Tue, Mar 29, 2011 at 12:47 PM, hendra kusuma
<penguinroad@gmail.com>wrote:

>> app large lists are rare, so I haven't looked into it fully).
>>
>> The other thing you should do is avoid things like each().
>> keep trying to do things in different ways to see which
> I guess I need to throw some trial and error a little bit
>
> btw, I have zero knowledge of C.
>
>
damn, I stuck
at best I can only get 15 sec. It's way too long, considering the same
program I make back then using delphi can load same data within 1 sec.

Problem is when I must loop resultset to use with iter.set_value
setting the value using array of string is faster when displaying,
but converting resultset to array of string also get me 15 sec -_-;

and I already disconnect the model from tree and use freeze_notify to
help
speeding up the process

any other suggestion? People? Please? Anything would be helpful
Database using Sequel with Postgresql
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.