# Help with liststore

**URL:** <https://www.ruby-forum.com/t/help-with-liststore/205057>\
**Category:** Ruby-Gnome 2\
**Created:** [March 28, 2011, 5:54pm UTC](https://www.ruby-forum.com/t/help-with-liststore/205057 "2011-03-28T17:54:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 28, 2011, 5:54pm UTC](https://www.ruby-forum.com/t/help-with-liststore/205057/1 "2011-03-28T17:54:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hendra\_kusuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/5f8ce5/32.png) [@hendra\_kusuma](https://www.ruby-forum.com/u/hendra_kusuma)\
**Post date:** [March 29, 2011, 4:24am UTC](https://www.ruby-forum.com/t/help-with-liststore/205057/2 "2011-03-29T04:24:12Z")

</div>

On 29 March 2011 00:46, hendra kusuma [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

```

---

<div class="post-metadata">

**Author:** ![hendra\_kusuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/5f8ce5/32.png) [@hendra\_kusuma](https://www.ruby-forum.com/u/hendra_kusuma)\
**Post date:** [March 29, 2011, 6:48am UTC](https://www.ruby-forum.com/t/help-with-liststore/205057/3 "2011-03-29T06:48:20Z")

</div>

On Tue, Mar 29, 2011 at 10:23 AM, Mike C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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.

---

<div class="post-metadata">

**Author:** ![hendra\_kusuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/5f8ce5/32.png) [@hendra\_kusuma](https://www.ruby-forum.com/u/hendra_kusuma)\
**Post date:** [March 29, 2011, 9:32am UTC](https://www.ruby-forum.com/t/help-with-liststore/205057/4 "2011-03-29T09:32:57Z")

</div>

On Tue, Mar 29, 2011 at 12:47 PM, hendra kusuma  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)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
