Newsgroups: gnu.misc.discuss,comp.lang.tcl,comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news.harvard.edu!news2.near.net!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!swrinde!news.uh.edu!uuneo.neosoft.com!nmtigw!peter
From: peter@nmti.com (Peter da Silva)
Subject: Improving Tcl performance
	Re: What should an alternative look like? was Re: Why you should not
Message-ID: <id.NTCD1.VIE@nmti.com>
Followup-To: comp.lang.tcl
Sender: peter@nmti.com (peter da silva)
Organization: Network/development platform support, NMTI
References: <366u7n$9b7@agate.berkeley.edu> <kD30sc2w165w@sytex.com> <id.14CD1.4IL@nmti.com> <368k4h$99m@erinews.ericsson.se>
Date: Tue, 27 Sep 1994 16:27:39 GMT
Lines: 29
Xref: glinda.oz.cs.cmu.edu gnu.misc.discuss:18377 comp.lang.tcl:19406 comp.lang.scheme:9977

In article <368k4h$99m@erinews.ericsson.se>,
Michael Salmon <etxmesa@eos.ericsson.se> wrote:
> I've been thinking a bit about a compiler for Tcl and a fairly simple
> approach seems to me to do something similar to PostScripts bind i.e.
> resolve all names so that you don't have to look them up.

The Tcl name lookup mechanism makes name lookup relatively cheap in
loops and the like... frequently resolved names are found quicker. A
bigger cost is reparsing strings.

What I thought would be useful would be to cache data: when you have a proc
you build a linked list of each string in it. Then for the control structures
you build a secondary chain, and so on. This would bring the pasring cost
of Tcl up to the level of lisp, and would be a much bigger win than pre-
resolving all names (of course names like "if" and "while" would be pre-
resolved in this scheme).

What you'd do is add an argument to Tcl_Interp that's a pointer to a cache
structure. When you pass a string to Tcl_Interp and the pointer was non-null
it would assume it was valid, and cache any newly resolved code into it as
it found it. It would contain structures corresponding to the standard tcl
control structures, and when it saw them it would call Tcl_Interp appropriately
with a virgin cache pointer, then save whatever got parsed through that time
when the code returned...
-- 
Peter da Silva                                            `-_-'
Network Management Technology Incorporated                 'U`
1601 Industrial Blvd.     Sugar Land, TX  77478  USA
+1 713 274 5180                       "Hast Du heute schon Deinen Wolf umarmt?"
