|
2025-03-29
| ||
| 18:37 | • Ticket [0b3595a819] Invocation of imported nested command is affected by recursi... artifact: 2759556f9e user: sebres | |
| 18:07 | • Ticket [0b3595a819]: 4 changes artifact: dd28e35961 user: sebres | |
| 18:07 | • New ticket [0b3595a819]. artifact: 13ebf0458e user: sebres | |
Invocation of imported nested command is affected by recursionlimit and has O(n) instead of O(1)
- is affected by recursionlimit of interpreter;
- has O(n) instead of O(1) by command invocation;
PoC:
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 }
}
Firstly it'd fail (due to incorrect exceeding of limit) with "too many nested evaluations (infinite loop?)"...
By repeat after interp recursionlimit {} 100000, the result would look like:
=== 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
If solved, it looks like this (without the necessity to increase recursionlimit):
=== 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
I'll provide the fix for this together with [62dafd9c53882dc2] (back-ported from my fork in the single branch).