Skip to content
Tcl Source Code History Of Ticket 1737021fffffffffffffffffffffffffffffffff
Login

History Of Ticket 1737021fffffffffffffffffffffffffffffffff

Artifacts Associated With Ticket 1737021fffffffffffffffffffffffffffffffff

  1. Ticket change [a1960f58e4] (rid 109749) by nobody on 2007-06-14 09:51:55:

    1. assignee initialized to: "pvgoran"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      A small program (attached) takes 2 seconds to operate. It contains a single switch statement executed 10000 times.
      
      When you slighly modify one of the patterns (put a ^ in front of it), the execution time is multiplied by 9i (it then takes about 20 seconds to operate). This seems unacceptable to me.
      
      This has been observed under at least Cygwin, GNU/Linux and Solaris 8. My e-mail address is Denis.Excoffier AT free.fr.
      
    4. foundin initialized to: "obsolete: 8.5a6"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "nobody"
    10. subsystem initialized to: "43. Regexp"
    11. title initialized to: "unacceptable performance gap for switch"
    12. type initialized to: "Bug"
  2. Ticket change [5abb09ec01] (rid 118194) by nobody on 2007-06-14 16:51:55:

    1. icomment:
      
      
      File Added - 233011: tclunefficient
      
      
      
    2. login: "[email protected]"
    3. mimetype: "text/plain"
    4. username: "[email protected]"
  3. Add attachment "tclunefficient" [8ea6281c13] (rid 120148) by [email protected] on 2007-06-14 16:51:55.

  4. Ticket change [79448d37eb] (rid 90097) by dkf on 2007-06-14 17:08:36:

    1. assignee changed to: "dkf"
    2. closedate changed to: "2007-06-14T10:08:36"
    3. closer changed to: "dkf"
    4. icomment:
      Logged In: YES 
      user_id=79902
      Originator: NO
      
      I'm not quite sure what I'm supposed to do to trigger the change (all the patterns already have ^ characters!) but I would note that you seem to be going out of your way to make your code inefficient. In particular, you use lots of runtime-generated patterns, which means that you defeat both the in-value and per-thread RE caches, forcing recompilation of each pattern every time through the loop. That sucks, but you've managed to create a horrible degenerate case.
      
      If you change your code so that you keep each *whole* RE in the "global" array instead of just fragments, you'll find the code goes much faster. (Alternatively, use fewer REs so that the per-thread cache isn't exceeded, but that might not be easy with real-life REs.)
      
      Otherwise, I've no idea what I'm supposed to do about this to magically make your code efficient. (Caching RE fragments would be horribly tricky to implement - it requires lots of changes in lots of places, including wholly new APIs - but that's the only thing I can think of which would guarantee to make your code zippy...)
      
      
    5. login: "dkf"
    6. mimetype: "text/plain"
    7. resolution changed to: "Wont Fix"
    8. status changed to: "Pending"
    9. username: "dkf"
  5. Ticket change [ae85df87d0] (rid 101653) by nobody on 2007-06-14 17:48:50:

    1. icomment:
      Logged In: NO 
      
      Sorry for that, the program included already has the ^ at the beginning of the line containing "v30".
      If you remove the ^ in this line, the program goes 9 times faster.
      
      The problem is not on the performance itself, but on the difference of execution times with or without this
      ^ in front of the "v30" line.
      
      
    2. login: "[email protected]"
    3. mimetype: "text/plain"
    4. status changed to: "Open"
    5. username: "[email protected]"
  6. Ticket change [ec9f011614] (rid 103738) by dkf on 2007-06-14 21:10:52:

    1. icomment:
      Logged In: YES 
      user_id=79902
      Originator: NO
      
      I *think* the thread-cache can hold 30 elements, and so if one of the REs in your example is spilled to a variable (or a literal), it turns out that all the RE compilations become cached (either in Tcl_Obj value caches or in the thread-cache) and that makes things much faster. I'm not keen on tweaking the size of the thread-cache, since it is a cost paid for by everyone; you can get better performance by doing something like this:
        # _Once_ only...
        foreach {k v} [array get global] {
           set re($k) ^$v
        }
        # In the loop
        global re
        switch -regexp -- $x $re(v00) - $re(v01) - $re(v02) - $re(v03) - ... {
           ....
        }
      
      If you use *that*, you'll find that things go faster (since the re array will manage the caches for you).
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  7. Ticket change [a44452b00c] (rid 110183) by dkf on 2007-06-14 21:11:12:

    1. closedate changed to: "2007-06-14T14:11:12"
    2. closer changed to: "dkf"
    3. status changed to: "Pending"
  8. Ticket change [9d8dd89bb9] (rid 96327) by nobody on 2007-06-14 22:57:28:

    1. icomment:
      Logged In: NO 
      
      Thank you for all: the explanations, and the hint that storing the RE (in its entirety) in a global variable allows the interpreter to compile it only once.
      
      Those interested in enlarging the thread-cache can probably try to modify "#define NUM_REGEXPS 30" in ./generic/tclRegexp.c.
      
      
      
      
      
      
    2. login: "[email protected]"
    3. mimetype: "text/plain"
    4. status changed to: "Open"
    5. username: "[email protected]"
  9. Ticket change [bf45d049b1] (rid 102223) by dkf on 2007-06-16 21:02:20:

    1. closedate changed to: "2007-06-16T14:02:20"
    2. closer changed to: "dkf"
    3. status changed to: "Closed"