Lists are Slow in Vala

The other day I wrote a small program in Python. Part of the program involved reading a text file, parsing the information, then appending the information line-by-line to two lists inside a loop. It worked well and it worked pretty quickly but I decided I wanted to try rewriting the program in Vala, which is a programming language somewhat similar to Java and should be fairly familiar to Java developers. Vala cross-compiles its code into C before compiling the C code so I thought recreating the program in Vala would make it even faster.

All of the normal elements of the program, reading the file, parsing it, did work fairly quickly. But appending the data to the lists was incredibly slow. Whereas the Python program was able to do it almost instantly, the Vala program took a good 15 or 20 seconds to do the same thing. I tried a number of different things to make sure it was appending the data to the lists that was causing the program to be slow, and that is indeed what it was.

The only reason I can think of for this is because Vala converts the program into C and dynamic lists aren’t something C natively supports, Vala must have to do some sort of gymnastics to get the Vala lists to work in the translated C code.

Whatever the reason, I’ll just be sticking to Python for my projects.

Leave a Reply

Copyright ©2017 Magic Kazoo Media
%d bloggers like this: