Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Speedup for [uplevel] and [upvar]

Closed / Accepted1037357fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 22 years ago
Descriptionplain2004-09-29 22:59:22
This patch speeds up [uplevel] and [upvar] by caching
the result of parsing the string form of the level
indicator in the Tcl_Obj argument instead of always
working with the string form for everything.
dkfplain2004-09-30 05:59:22
File Added - 103249: objup.diff
dgpplain2004-09-30 06:42:13
File Added - 103256: 1037357.patch

Logged In: YES 
user_id=80530

corrected  patch applies and compiles.
dgpplain2004-09-30 06:47:46
Logged In: YES 
user_id=80530

The comments in Tcl*GetFrame
say "modify the interpreter", but
neither routine actually does that.
dgpplain2004-09-30 07:15:49
File Deleted - 103256: 



File Added - 103261: 1037357.patch

Logged In: YES 
user_id=80530

updated patch takes care of comments
and allows `make genstubs` to succeed.
dgpplain2004-09-30 08:10:58
Logged In: YES 
user_id=80530

something about the patch
breaks tcltest:

dict.test
Test file error: can't rename "::tcltest::Replace::Puts":
command doesn't exist
    while executing
"rename [namespace current]::Replace::Puts ::puts"
    (procedure "::tcltest::Eval" line 16)
    invoked from within
"::tcltest::Eval {::tcltest::RunTest dict-18.2 {# Test that
the dictionary is a valid list
        set d [dict create "abc def" 0 "a\{b" 1 "c\}d" 2]
  ..."
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 [list [namespace origin Eval] $command 1]"
    (procedure "test" line 126)
    invoked from within
"test dict-18.2 {dict-list relationship} {
    -body {
        # Test that the dictionary is a valid list
        set d [dict create "abc def" 0 "a\{b"..."
    (file "/local/src/tcl/tests/dict.test" line 726)
dgpplain2004-09-30 08:48:33
Logged In: YES 
user_id=80530


Root of the problem appears to
be line 1965 of tcltest.tcl where
the literal "1" appears twice.
First as the "level" argument
to [uplevel] and second as an
argument in the command to
be evaluated up a level.  Something
isn't shimmering right, I'd suspect.

As a check, if I remove the second "1"
from that line (and accept the default
value of that argument, which is 1),
then the problem goes away.
dgpplain2004-09-30 09:31:12
Logged In: YES 
user_id=80530


This patch should be checked
against tclbench.  I suspect that
whatever is being saved by
repeated use of $level by 
multiple [uplevel]s and [upvar]s
is more than being lost by
the greatly increased shimmering of
the literal constant "1" in so many
logical expressions.

`make test` sure feels a lot slower anyway.
dkfplain2004-09-30 15:13:51
Logged In: YES 
user_id=79902

Thanks for the review; I'll have to write a new version that
is aware of numeric types and avoids the conversion in those
situations. I suspected I needed to do this anyway ;^)
dkfplain2004-09-30 22:36:51
Logged In: YES 
user_id=79902

Here's a version that shouldn't have problems with
shimmering all over the place.  Causes no new test failures.
 No idea (formally) what happens in tclbench, but looks good
in informal trials. ;^)
dkfplain2004-09-30 22:36:52
File Added - 103339: 1037357_2.patch
dkfplain2004-09-30 22:37:12
File Deleted - 103249:
dgpplain2004-09-30 22:52:03
Logged In: YES 
user_id=80530

revised patch tests ok.
dkfplain2004-10-01 19:46:02
Logged In: YES 
user_id=79902

Applied to HEAD
Log in (anonymous is fine) to add a comment.

Attachments: