Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: c7383a10cccb00f41d57b0ae60961f15dd7b55ac0e2e08dee79f1c0d19b0ed77
Ticket: 62dafd9c53882dc27f4bbd68ad5b2160f06129ff
Namespace import can cause quadratic big-O and affects all siblings of same original command
User & Date: sebres on 2025-03-27 13:53:45
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    <code>[namespace import]</code> looks to be affected by quadratic big-O... 
    Every NS, OO-context, etc importing the command causes that it's deletion costs <code>O(n**2)*m</code>, where <code>n<code> - number of imports for original command, and <code>m</code> - number of such imported commands in NS/OO/etc.
    
    PoC:
    <code><pre>
      namespace eval A { proc c1 {} {}; proc c2 {} {}; proc c3 {} {}; namespace export * }
      proc create {ns} { namespace eval $ns { namespace import ::A::* } }
      foreach count {100 1000 10000 100000} {
        puts "=== $count ==="
        set i 0; puts [timerate { create ::B[incr i]; } 1000 $count]
        set i 0; puts [timerate { namespace delete ::B[incr i]; } 1000 $count]
      }
    </pre></code>
    result:
    <code><pre>
      === 100 ===
      26.0500 µs/# 100 # 38387.7 #/sec 2.605 net-ms
      2.540000 µs/# 100 # 393700 #/sec 0.254 net-ms
      === 1000 ===
      13.8020 µs/# 1000 # 72453.3 #/sec 13.802 net-ms
      9.236000 µs/# 1000 # 108271 #/sec 9.236 net-ms
      === 10000 ===
      11.0121 µs/# 10000 # 90809.2 #/sec 110.121 net-ms
      285.814 µs/# 3498 # 3498.8 #/sec 999.776 net-ms
      === 100000 ===
      10.9604 µs/# 90967 # 91237.9 #/sec 997.031 net-ms
      14274.5 µs/# 70 # 70.055 #/sec 999.212 net-ms
    </pre></code>
    (the last two are not achieved the whole set (would take a small eternity for the last), it has mastered only 70 deletions in a second, where on previous order of magnitude it was 3.5k in a second).
    
    Causation is <code>ImportRef *importRefPtr</code> in <code>Command</code> structure, what is unidirectional list.
    Moreover it's existence is not justified at all - this causes drastic performance impacts in any cases, and basically needed only to pass namespace-56.6 (deletion of original command shall cause the invocation of deletion-traces on imported commands).
    This (if needed at all) can be achieved with other way without that list.
    
  5. foundin changed to: "any"
  6. is_private changed to: "0"
  7. login: "sebres"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "50e9528765c18296566374b3fde2df942c394efd"
  10. resolution changed to: "None"
  11. severity changed to: "Severe"
  12. status changed to: "Open"
  13. submitter changed to: "sebres"
  14. subsystem changed to: "- New Builtin Commands"
  15. title changed to:
    Namespace import can cause quadratic big-O and affects all siblings of same original command
    
  16. type changed to: "Bug"