Skip to content
Tcl Source Code History Of Ticket f97d4ee020
Login

History Of Ticket f97d4ee020

Artifacts Associated With Ticket f97d4ee020

  1. Ticket change [cadd7eebc0] (rid 141433) by msofer on 2015-03-22 20:02:10:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      Reported by emiliano in the chat: the following script shows quadratic (?) behaviour in namespace deletion.
      
      foreach n {1 10 100 1000 10000 100000} {
          set i 0
          puts "--- $n ---"
          puts [time {namespace eval test::ns#$i {}; incr i} $n]
          puts [time {namespace delete test}]
      }
      
    5. foundin initialized to: "8.6.4"
    6. is_private initialized to: "0"
    7. login: "msofer"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "214bb5765a5d2d4513fe393de9e8c8431e3e869a"
    10. resolution initialized to: "None"
    11. severity initialized to: "Important"
    12. status initialized to: "Open"
    13. submitter initialized to: "msofer"
    14. subsystem initialized to: "21. [namespace]"
    15. title initialized to: "quadratic bheaviour in namespace deletion"
    16. type initialized to: "Bug"
  2. Ticket change [97804fd2f1] (rid 141434) by msofer on 2015-03-22 21:20:14:

    1. icomment:
      The problem is not new: same behaviour observed in 8.5.0 and 8.4.15
      
    2. login: "msofer"
    3. mimetype: "text/plain"
  3. Ticket change [fbdbe9af2a] (rid 141437) by dgp on 2015-03-22 22:30:43:

    1. icomment:
      
      Trouble is in "safe" teardown of big hash tables.
      
      See bugfix branch for demo of proper linear
      performance but with at least risk if not reality
      of improper functioning.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  4. Ticket change [06e96baa5b] (rid 141446) by sebres on 2015-03-23 08:41:45:

    1. icomment:
      I'm not sure the suggested "bugfix" with Tcl_NextHashEntry would be good. It's not safe (segfaults) when within cycle with Tcl_NextHashEntry the hash will be modified (Tcl_DeleteHashEntry).
      In addition I'm not sure all the entries will be affected (because of rebuild of hash within).
      The "proper" fix can be something like mark the hash as "will_be_deleted", to prevent rebuild bucket chains during deletion.
      
    2. login: "sebres"
    3. mimetype: "text/plain"
  5. Ticket change [54bd8797be] (rid 141447) by sebres on 2015-03-23 08:48:07:

    1. icomment:
      BTW, namespace oriented OO systems like Itcl can create again a child namespace (in destructor of it), so Tcl_NextHashEntry either makes a segfault or not affect this new child namespace - memory leak or segfault later (because no parent hash object).
      
    2. login: "sebres"
    3. mimetype: "text/plain"
  6. Ticket change [82e32651be] (rid 141448) by dgp on 2015-03-23 12:24:16:

    1. icomment:
      
      Yes, the branch as it is cannot be accepted as a fix.
      It is committed only to simplify the ability for anyone
      concerned to be satisfied that it is this design matter
      that is the source of the bad performance.  There's no
      need to look for any additional causes.  This explains it.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  7. Ticket change [4c80005b60] (rid 141455) by dgp on 2015-03-24 14:16:59:

    1. icomment:
      
      Re-titled to more precisely identify the problem.
      
      Hash table teardown is O(N^2) in the number
      of table entries, unless one can guarantee that
      the teardown loop is the only thing changing the
      table.  That is, no callbacks!
      
      Destructor callbacks are common in much of
      the Tcl implementation, so we can expect to
      hit this performance issue in many places.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. title changed to: "quadratic cost of hash table teardown"
  8. Ticket change [fb431d951a] (rid 142557) by dgp on 2015-07-20 12:13:51:

    1. assignee changed to: "dkf"
    2. icomment:
      
      Raise prio.  More folks are noticing this problem.
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. priority changed to: "7 High"
  9. Ticket change [b939e8c35d] (rid 142563) by aku on 2015-07-21 22:37:24:

    1. icomment:
      Given the problem with destructor callbacks ...
      
      Might it make sense to split tear-downs involving hash-tables into two phases ?
      
      Phase 1: Mark structures as gone/dead/whatever, run callbacks. - Linear
      
      Phase 2: Do actual tear-down, linear.
      
    2. login: "aku"
    3. mimetype: "text/plain"
  10. Ticket change [b8a5f4657a] (rid 142564) by dgp on 2015-07-22 14:08:10:

    1. icomment:
      
      Open to a patch along those lines, but I have my doubts.
      
      I suspect that most of the cost is repeatedly scanning over
      empty buckets since Tcl_FirstHashEntry() always starts looking
      at bucket 0.
      
      Would improve things (enough?) to arrange for a circular
      bucket search to have a start/stop point determine by the
      value of searchPtr->nextIndex first passed to Tcl_FirstHashEntry().
      And then have repeated Tcl_FirstHashEntry() calls remember where
      we were last looking.
      
      The snag is that the obvious way to do such a thing appears to
      require modifying fields in public structs.
      
      Might be worth a demo on a branch, just to see if it's effective,
      and then try to conjure some workaround of the non-opaque struct
      corner we've painted ourselves into.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  11. Ticket change [62f311f4a2] (rid 142565) by dgp on 2015-07-22 14:13:09:

    1. icomment:
      
      A related design issue (perhaps mentioned in another ticket somewhere?)
      is that HashTables are coded to only grow and never shrink.  So even
      when a hash table holds only one entry, if the table was ever big, that
      one entry sits in an ocean of empty buckets, and on average half of
      them need scanning for T_FHE() to find it.
      
      Hmmmm.... It appears that T_FHE() called on an empty table is still
      required to scan all the buckets?!  We don't have a size value?
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  12. Ticket change [887ac07f81] (rid 142566) by dgp on 2015-07-22 14:23:55:

    1. icomment:
      
      The Tcl_HashTable struct does indeed have a numEntries field.
      
      Seems at least we could notice when it holds 0 and escape
      without the scan (and perhaps reset the empty table to the
      staticBuckets initial configuration?).
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  13. Ticket change [5765b4cf3f] (rid 142569) by dkf on 2015-07-23 13:37:18:

    1. icomment:
      The simplest possible thing would be to try using <tt>Tcl_NextHashEntry</tt> during the teardown instead of <tt>Tcl_FirstHashEntry</tt>. The only reason for using the other one is if you are adding elements during the teardown; if we can confirm that that won't happen, we won't hit problems since <tt>Tcl_NextHashEntry</tt> is safe for the iteration/deletion pattern.
      <p>
      Callbacks are OK provided they don't modify the hash table itself. Some sort of flag in the entries (not the <tt>Tcl_HashEntry</tt> but the things they point to) and another in the structure containing the hash table might be enough. I'd like to avoid putting the smarts in the <tt>Tcl_HashTable</tt> system itself as that's already quite complicated enough for a fundamental data structure.
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. priority changed to: "8"
    5. username: "dkf"
  14. Ticket change [3984ce5301] (rid 142599) by dkf on 2015-07-24 13:50:04:

    1. icomment:
      The bucket scan wouldn't matter, except that it's being repeated. It only needs to be repeated if any entry <i>other than the current one</i> was structurally changed. (Well, changes after the current entry are fine too. But that's happenstance.)
      <p>
      I wonder what happens if we put a flag in to detect whether a concurrent non-delete modification occurred? (It's the damn deletion callbacks…)
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. username: "dkf"
  15. Ticket change [64eb019122] (rid 142600) by dkf on 2015-07-24 13:58:55:

    1. icomment:
      For an example of why you can get into trouble with callbacks, try this script:
      <pre>
      oo::class create Foo {
          variable i
          constructor x {set i [incr x]}
          destructor {Foo create ::abc::$i $i}
      }
      namespace eval abc {Foo create 1 1}
      namespace delete abc
      </pre>
      Just don't expect it to return soon!
      <p>
      We ought to do something to stop commands (or namespaces, or sub-namespaces) from being created in namespaces that are being deleted. At least then we'd get a sensible failure.
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. username: "dkf"
  16. Ticket change [2ead6b59e4] (rid 142705) by dkf on 2015-08-02 16:24:04:

    1. icomment:
      Updated the title: this is a namespace problem, not a hash table problem.
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. title changed to: "quadratic cost of namespace teardown"
    5. username: "dkf"
  17. Ticket change [2628f433e3] (rid 142707) by dkf on 2015-08-02 16:52:36:

    1. icomment:
      The real issue is that <tt>Tcl_FirstHashEntry</tt> is being used repeatedly, since that does a linear scan from the beginning of the list of buckets. At the very least, the cleanup code should avoid that. It's not the responsibility of the hash table code to make people use its API correctly.
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. username: "dkf"
  18. Ticket change [04e33603c8] (rid 146733) by dkf on 2016-05-16 10:59:53:

    1. icomment:
      Please review commit [20c01f4161d1b69d]. Passes test suite for me and does not have quadratic behaviour with motivating test case.
      
    2. login: "dkf"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "dkf"
  19. Ticket change [d2f539c75b] (rid 146734) by adrianmedranocalvo on 2016-05-17 09:47:27:

    1. icomment:
      The patch fixes [e76f0a6ca52a2ff3c2b1e9cb2585f3de0c44ab5d], which was about namespaces with very many commands.  Thank you!
      
    2. login: "adrianmedranocalvo"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "Adrián Medraño Calvo <[email protected]>"
  20. Ticket change [0cfdf28071] (rid 146740) by dgp on 2016-05-17 14:48:02:

    1. icomment:
      
      Patch is effective and appears correctly coded.
      
      I say merge.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  21. Ticket change [81f9d39ecf] (rid 146757) by dgp on 2016-05-20 11:53:25:

    1. icomment:
      
      I see new tests, but I don't see them fail.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  22. Ticket change [5a52539ee4] (rid 146766) by dkf on 2016-05-21 09:28:58:

    1. closedate changed to: "2457529.89512331"
    2. closer changed to: "dkf"
    3. icomment:
      Tests were only failing in mem-debug mode (the problem was writing to freed memory).
      
      Fixed and merged.
      
    4. login: "dkf"
    5. mimetype: "text/x-fossil-wiki"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "dkf"