Re: Is there already a "sourcecode to optimized converter" for tcl?



There is a bytecode compiler built into the Tcl interpreter. Anything
inside a proc gets bytecode compiled the first time that proc is
called. The ActiveState Tcl compiler "remembers" the compiled form of
your code, which means you save a miniscule amount of time when you
first run the program (because the compilation is already done), but
once the code is bytecode-compiled, it will run at the same speed
whether the file you sourced was compiled or not. (ActiveState makes
no bones about the fact the goal of their compiler is not to improve
performance but to protect intellectual property.)

So your code is already getting optimized--the bytecode compiler will
take care of any issues that arise due to comments or white space. If
your bytecode-compiled code is not fast enough for you, here are some
steps to take:

* identify places where you're not taking advantage of optimizations
in Tcl. For example, have you put your expressions inside curly
braces (e.g. [expr {$myvar * 2}] rather than [expr $myvar * 2])?
http://wiki.tcl.tk/348 is a good starting place to learn about
performance tweaks.

* identify bottlenecks in your code and optimize those algorithms. If
you can boil down those bottlenecks to minimal examples, I'm sure
readers of c.l.t. can help you maximize their efficiency.

* if things are still too slow for you, consider rewriting the slow
parts in C as a Tcl extension.

Throughout this process, the [time] command is your friend. Whenever
possible, make sure to time several iterations of the code in question
(e.g., [time {myproc} 1000]) to minimize the effect of unusually slow
iterations. At a minimum, call the proc once before timing it
(otherwise you end up timing bytecode compilation AND code execution,
which will seriously confound your results).

Hope that helps,
Aric

.



Relevant Pages

  • Re: TCL vs. Perl
    ... If you include this embedded compiler only for situations where the ... Tcl does. ... interpreter) to do the right thing. ... proc unknown { ...
    (comp.lang.tcl)
  • Re: question about functions generating functions
    ... The ANSI CL standard requires you to have a compiler. ... the bytecode compiler of CLISP is a 'real' compiler. ...
    (comp.lang.lisp)
  • Re: question about functions generating functions
    ... The ANSI CL standard requires you to have a compiler. ... don't think a bytecode compiler like in CLISP is a REAL compiler or   ...
    (comp.lang.lisp)
  • Re: AJAX for Tcl web servers, like tclhttpd or wub
    ... The compiler runs as a Java servlet, ... maniplate those within TCL with easy to learn syntax. ... the plugin outputs JaveScript and has direct access to ... Lots and lots of responces and ideas are always welcome. ...
    (comp.lang.tcl)
  • Re: TCL vs. Perl
    ... I started this discussion about TCL versus other ... Perl has binary compiler, but is actually not machien code, but some ... I thought any interpreted language could be compiled into machine code. ... set channel ...
    (comp.lang.tcl)