ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> tcl-core
tcl-core
Re: [TCLCORE] Tcl through X rays
by Mo DeJong other posts by this author
May 28 2007 4:37PM messages near this date
Re: [TCLCORE] Tcl through X rays | Re: [TCLCORE] Tcl through X rays
Alexandre Ferrieux wrote:
>  Hello Mo,
>   
>  On 5/28/07, *Mo DeJong* <mo@[...].com <mailto:mo@[...].com>> wrote:
> 
>       You can write a compiler that assumes that a
>      proc does not deal with linked variables,
>      but it is trivial to create a test case that breaks this
>      optimization. 
> 
>   
>  Yes, if we do nothing actively to deal with upvars.
>  But I was thinking about intercepting those accesses at runtime (see 
>  my answer to Donal's).
Yes, but then you end up with a least common denominator approach. You 
end up having to check
for traces and other changes before each variable access as well as 
changes to command epochs before
each command invocation. All these checks to deal with the most unlikely 
cases waste much CPU time.

If you ask me, the right way to create an optimized Tcl compiler is to 
provide a way to declare procs
that don't "do anything funky". This includes upvars, uplevels, traces 
vars, and so on. Basically, a
proc would declare that it will not mess with variables in calling 
scopes and that other procs invoked
by the command will not mess with variables in the current scope. The 
runtime would also need to
ensure that crazy edge cases like the "set" command being redefined 
while the proc is running don't happen.

With the runtime enforcing these rules, a command that does no do 
anything crazy could invoke another
command that does nothing crazy without having to check for every 
possible edge case. Simple procs
like the following could be significantly optimized:

proc_non_funky { arg } {
    set sum 0
    for {set i 0} {$i < 1000} {incr i} {
        incr sum $i
    }
    return $sum
}

In this command, 3000 checks on the variable i could be avoided, along 
with 1000 checks on the variable sum.
It really adds up.

cheers
Mo DeJong


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Tcl-Core mailing list
Tcl-Core@[...].net
https://lists.sourceforge.net/lists/listinfo/tcl-core
Thread:
Alexandre Ferrieux
Donal K. Fellows
Alexandre Ferrieux
Mo DeJong
Alexandre Ferrieux
Mo DeJong
Jeff Hobbs
Andreas Leitgeb
Donal K. Fellows
Alexandre Ferrieux
Larry McVoy
Donal K. Fellows
Donal K. Fellows
Alexandre Ferrieux
Miguel Sofer
Rna020
Donal K. Fellows
Donal K. Fellows
Gerald W. Lester
Donal K. Fellows

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved