Skip to content
Tcl Source Code History Of Ticket 0b3595a8191076b0
Login

History Of Ticket 0b3595a8191076b0

Artifacts Associated With Ticket 0b3595a8191076b0

  1. Ticket change [13ebf0458e] (rid 238760) by sebres on 2025-03-29 18:07:18:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. comment initialized to:
      Similar to [62dafd9c53882dc2], but this time it is about execution and going to missing direct pointer to the real command by nesting the imports (e. g. like nested inheritances of NS) - during the execution it always need to iterate over all nested imports up to the real command and therefore:
      <ol>
      <li>is affected by recursionlimit of interpreter;</li>
      <li>has O(n) instead of O(1) by command invocation;</li>
      </ol>
      
      PoC:
      <code><pre>
        namespace eval ::A { proc c {} {}; namespace export * }
        foreach count {100 1000 10000} {
          puts "=== $count ==="
          for {set i 0} {$i < $count} {} {
            if {$i} {
              set imp "namespace import -force ::B${i}::*"
            } else {
              set imp "namespace import -force ::A::*"
            }
            namespace eval ::B[incr i] "$imp; namespace export *"
          }
          puts [timerate " ::B${i}::c " 1000]
          while {$i} { namespace delete ::B$i; incr i -1 }
        }
      </pre></code>
      
      Firstly it'd fail (due to incorrect exceeding of limit) with "too many nested evaluations (infinite loop?)"... 
      
      Hereafter by repeat after <code>interp recursionlimit 100000</code>, the result would look like:
      <code><pre>
        === 100 ===
        3.397699 µs/# 291567 # 294316 #/sec 990.657 net-ms
        === 1000 ===
        40.9938 µs/# 24375 # 24393.9 #/sec 999.225 net-ms
        === 10000 ===
        467.815 µs/# 2137 # 2137.6 #/sec 999.721 net-ms
      </pre></code>
      
      If solved, it looks like this (without the necessity to increase recursionlimit):
      <code><pre>
        === 100 ===
        0.202850 µs/# 4249839 # 4929744 #/sec 862.081 net-ms
        === 1000 ===
        0.206966 µs/# 4176792 # 4831722 #/sec 864.452 net-ms
        === 10000 ===
        0.201285 µs/# 4278305 # 4968083 #/sec 861.158 net-ms
      </pre></code>
      
      I'll provide the fix for this together with [62dafd9c53882dc2] (back-ported from my fork in the single branch).
      
    5. is_private initialized to: "0"
    6. login: "sebres"
    7. priority initialized to: "5 Medium"
    8. private_contact initialized to: "50e9528765c18296566374b3fde2df942c394efd"
    9. resolution initialized to: "None"
    10. severity initialized to: "Severe"
    11. status initialized to: "Open"
    12. submitter initialized to: "sebres"
    13. subsystem initialized to: "21. [namespace]"
    14. title initialized to:
      Invocation of imported nested command is affected by recursionlimit and has O(n) instead of O(1)
      
    15. type initialized to: "Bug"
  2. Ticket change [dd28e35961] (rid 238761) by sebres on 2025-03-29 18:07:57:

    1. assignee changed to: "sebres"
    2. foundin changed to: "any"
    3. login: "sebres"
    4. mimetype: "text/plain"
  3. Ticket change [2759556f9e] (rid 238762) by sebres on 2025-03-29 18:37:05:

    1. comment changed to:
      Similar to [62dafd9c53882dc2], but this time it is about execution and going to missing direct pointer to the real command by nesting the imports (e. g. like nested inheritances of NS) - during the execution it always need to iterate over all nested imports up to the real command and therefore:
      <ol>
      <li>is affected by recursionlimit of interpreter;</li>
      <li>has O(n) instead of O(1) by command invocation;</li>
      </ol>
      
      PoC:
      <code><pre>
        namespace eval ::A { proc c {} {}; namespace export * }
        foreach count {100 1000 10000} {
          puts "=== $count ==="
          for {set i 0} {$i < $count} {} {
            if {$i} {
              set imp "namespace import -force ::B${i}::*"
            } else {
              set imp "namespace import -force ::A::*"
            }
            namespace eval ::B[incr i] "$imp; namespace export *"
          }
          puts [timerate " ::B${i}::c " 1000]
          while {$i} { namespace delete ::B$i; incr i -1 }
        }
      </pre></code>
      
      Firstly it'd fail (due to incorrect exceeding of limit) with "too many nested evaluations (infinite loop?)"... 
      
      By repeat after <code>interp recursionlimit {} 100000</code>, the result would look like:
      <code><pre>
        === 100 ===
        3.397699 µs/# 291567 # 294316 #/sec 990.657 net-ms
        === 1000 ===
        40.9938 µs/# 24375 # 24393.9 #/sec 999.225 net-ms
        === 10000 ===
        467.815 µs/# 2137 # 2137.6 #/sec 999.721 net-ms
      </pre></code>
      
      If solved, it looks like this (without the necessity to increase recursionlimit):
      <code><pre>
        === 100 ===
        0.202850 µs/# 4249839 # 4929744 #/sec 862.081 net-ms
        === 1000 ===
        0.206966 µs/# 4176792 # 4831722 #/sec 864.452 net-ms
        === 10000 ===
        0.201285 µs/# 4278305 # 4968083 #/sec 861.158 net-ms
      </pre></code>
      
      I'll provide the fix for this together with [62dafd9c53882dc2] (back-ported from my fork in the single branch).
      
    2. login: "sebres"
    3. mimetype: "text/plain"