1
votes

This pertains to Tcl 8.5 Say I have a very large dictionary. From performance points of view (memory footprint, etc), assuming that I do not modify the dictionary, should upvar provide a massive performance improvement in terms of memory? I am using an EDA tool, which has TCL shell, but the vendor disabled the TCL memory command. I know that Tcl can share strings under the hood for performance... The same dictionary can be passed several nested procs' calls. Thanks.

2

2 Answers

1
votes

As long as you don't modify the dictionary, it won't provide much noticeable performance difference or memory-consumption difference.

Tcl passes values by immutable reference, and copies them when you write an update to them if they're shared, e.g., between a global variable and a local variable (procedure formal parameters are local variables). If you never change anything, you're going to use a shared reference and everything will be quick. If you do need to change something, you should use upvar or global (or one of the more exotic variants) to make a local variable alias to the caller's/global variable and change via that, as that's fastest. But that's only an issue if you're going to change the value.

0
votes

I would imagine that under the hood the dictionary isn't copied until it's written to so if there's no writes then you should be okay. Use a global if you want to be absolutely sure.

  proc myproc {} {
    global mydictionary
  }