Version 10 of Speed issues

Updated 2004-06-30 10:52:53 by dkf

This page is intended to document issues when effective execution of Tcl scripts is targeted. Please add any single topic below as to keep it as a comprehensive list. Append general comments as usual to the end of this page -- RJM.


  1. Write expr commands with the argument in curly braces whenever possible. This avoids conversion of numbers in strings and back. The speed impact may be a factor of 20 or so.
  2. Do not write procs without Arguments. Empty procs may execute approx. 4 times slower. At least speed critical procs schould be defined with a dummy argument. To be precise (according to comment of MS), procs without arguments are NOT the problem, only invocations without trailing character after command name. So invoke commands without arguments preferably as command; (trailing semicolon) as long as the bug is not fixed.
  3. ...


RJM: Referencing to (2) I can say that I found this by accident. On a Win98 machine with 266 MHz clock, the following execution times apply:

An empty proc without Arguments:

 % proc test {} {}
 % time {test} 1000
 95 microseconds per iteration

An empty proc with an Argument:

 % proc fast {x} {}
 % time {fast 5} 1000
 12 microseconds per iteration

I performed several variations, also with filled body and so on. The crucial differencs lies in defining a proc with or without an argument.


MSW: Actually calling a proc without an argument. For comparison:

 % time {test} 1000
 12 microseconds per iteration
 % time {fast 5} 1000
 3 microseconds per iteration
 % proc maybe {{empty {}}} {}
 % time {maybe} 1000
 13 microseconds per iteration
 % time {maybe empty} 1000
 3 microseconds per iteration

MS This is Bug #458361 [L1 ], but the interpretation is wrong: it is not proc calls without arguments that are slow, but rather scripts that consist of a single word and whose string equals a command name - which significantly reduces the likelihood of hitting the bug. Even adding a space to the script destroys the effect. Witness

 %  proc maybe {{empty {}}} {}
 % # call with argument
 % time {maybe empty} 10000  
 4 microseconds per iteration
 % # call without argument
 % time {maybe} 10000
 19 microseconds per iteration
 % # call without argument; space added
 %  time {maybe } 10000
 3 microseconds per iteration
 % # call without argument; semicolon added
 % time {maybe;} 10000
 4 microseconds per iteration
 % complex script, call with arguments
 % time {maybe empty; maybe empty} 10000
 7 microseconds per iteration
 % # complex script, call without arguments
 % time {maybe;maybe} 10000
 7 microseconds per iteration

Thanks, I have updated the issue list above accordingly --RJM

Hmmm ... not sure about the update; thinking about how to revise it. --MS

DKF: This is a shimmering effect between command names and scripts.