Tcl/Tk is fast and it blows my mind

Ro 2011 September

Tcl/Tk is fast and it blows my mind. What do I mean? Well let's take the program I'm writing right now, milkjack. It shows multiple peered text widgets, and each one in a movable window, all in a containing canvas frame to make an mdi interface.

I'm typically loading 50-150k files in it, and they happen to be mostly ascii, and I'm not really using the utf-8 encoding capabilities that I get for free when I use Tcl/Tk.

Now if I was doing that on a 3 GHz i7 no one would be surprised. But this is on a 200$ acer netbook, using an Atom, which is about equal to a 1 GHz Pentium III circa 2001. I get 6 hours on battery and run debian. I get slowness and real-life waiting when I use the windows explorer replacement in Gnome which is written in C, which is called Nautilus. Not in my Tcl/Tk programs. And I don't even brace my expr's because I think it uglifies the code.

I do tagging of the master text widget in another thread, the other peer widgets get the new tags automatically because they are peered. I have gone so far as to use threads this time, I have two seperate threads sitting there that have loaded the entire source code of the program, so they have every proc available to be called, as well as my custom console. So there is a lot of functionality available in each thread, with each thread having it's own '.' dot toplevel etc. And it's fast. On an Atom.

Why is the C coded Nautilus so slow? Well I guess you'd have to ask the Gnome guys, or maybe instrument the code and find out for yourself. I know for a fact that a hand-rolled tree in Tk based on the canvas would be lightning compared, and that's without getting into the speed of the Tk tree control, or into the features that abound in Nemethi's tablelist.

Graphical stuff is fast. What is slow in Tcl/Tk is when you start doing calculations. Do any amount of math and man do I hit slowdowns. So I find myself shying away from fun code that relies on more arithmetic because I just know I will hit some frustrating slowdowns.

Sure I can callout to C. At least the interface that Tcl exposes isn't too bad, even if C code is.

Still, I'm amazed at how fast so much GUI stuff is with Tcl/Tk.

DKF: I suspect that the speed is because the core engine of Tk was designed to be fast on hardware that was current 15 years ago. (I remember Tcl/Tk being fast then, beating Lispworks into a pulp in all observable categories relating to GUIs.) The speed is due to things like intelligent postponement of work (idle events are a brilliant invention) and use of good algorithms.