Skip to content
Tcl Source Code Artifact [13ebf0458e]
Login

Artifact [13ebf0458e]

Artifact 13ebf0458ee73abf0f529a14edba362aefa067dcb3af4e17a94d47de1b8239ba:

Ticket change [13ebf0458e] - New ticket [0b3595a8191076b0|0b3595a819] <i>Invocation of imported nested command is affected by recursionlimit and has O(n) instead of O(1)</i>. by sebres on 2025-03-29 18:07:18.
D 2025-03-29T18:07:18.503
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment Similar\sto\s[62dafd9c53882dc2],\sbut\sthis\stime\sit\sis\sabout\sexecution\sand\sgoing\sto\smissing\sdirect\spointer\sto\sthe\sreal\scommand\sby\snesting\sthe\simports\s(e.\sg.\slike\snested\sinheritances\sof\sNS)\s-\sduring\sthe\sexecution\sit\salways\sneed\sto\siterate\sover\sall\snested\simports\sup\sto\sthe\sreal\scommand\sand\stherefore:\r\n<ol>\r\n<li>is\saffected\sby\srecursionlimit\sof\sinterpreter;</li>\r\n<li>has\sO(n)\sinstead\sof\sO(1)\sby\scommand\sinvocation;</li>\r\n</ol>\r\n\r\nPoC:\r\n<code><pre>\r\n\s\snamespace\seval\s::A\s{\sproc\sc\s{}\s{};\snamespace\sexport\s*\s}\r\n\s\sforeach\scount\s{100\s1000\s10000}\s{\r\n\s\s\s\sputs\s"===\s$count\s==="\r\n\s\s\s\sfor\s{set\si\s0}\s{$i\s<\s$count}\s{}\s{\r\n\s\s\s\s\s\sif\s{$i}\s{\r\n\s\s\s\s\s\s\s\sset\simp\s"namespace\simport\s-force\s::B${i}::*"\r\n\s\s\s\s\s\s}\selse\s{\r\n\s\s\s\s\s\s\s\sset\simp\s"namespace\simport\s-force\s::A::*"\r\n\s\s\s\s\s\s}\r\n\s\s\s\s\s\snamespace\seval\s::B[incr\si]\s"$imp;\snamespace\sexport\s*"\r\n\s\s\s\s}\r\n\s\s\s\sputs\s[timerate\s"\s::B${i}::c\s"\s1000]\r\n\s\s\s\swhile\s{$i}\s{\snamespace\sdelete\s::B$i;\sincr\si\s-1\s}\r\n\s\s}\r\n</pre></code>\r\n\r\nFirstly\sit'd\sfail\s(due\sto\sincorrect\sexceeding\sof\slimit)\swith\s"too\smany\snested\sevaluations\s(infinite\sloop?)"...\s\r\n\r\nHereafter\sby\srepeat\safter\s<code>interp\srecursionlimit\s100000</code>,\sthe\sresult\swould\slook\slike:\r\n<code><pre>\r\n\s\s===\s100\s===\r\n\s\s3.397699\sµs/#\s291567\s#\s294316\s#/sec\s990.657\snet-ms\r\n\s\s===\s1000\s===\r\n\s\s40.9938\sµs/#\s24375\s#\s24393.9\s#/sec\s999.225\snet-ms\r\n\s\s===\s10000\s===\r\n\s\s467.815\sµs/#\s2137\s#\s2137.6\s#/sec\s999.721\snet-ms\r\n</pre></code>\r\n\r\nIf\ssolved,\sit\slooks\slike\sthis\s(without\sthe\snecessity\sto\sincrease\srecursionlimit):\r\n<code><pre>\r\n\s\s===\s100\s===\r\n\s\s0.202850\sµs/#\s4249839\s#\s4929744\s#/sec\s862.081\snet-ms\r\n\s\s===\s1000\s===\r\n\s\s0.206966\sµs/#\s4176792\s#\s4831722\s#/sec\s864.452\snet-ms\r\n\s\s===\s10000\s===\r\n\s\s0.201285\sµs/#\s4278305\s#\s4968083\s#/sec\s861.158\snet-ms\r\n</pre></code>\r\n\r\nI'll\sprovide\sthe\sfix\sfor\sthis\stogether\swith\s[62dafd9c53882dc2]\s(back-ported\sfrom\smy\sfork\sin\sthe\ssingle\sbranch).
J is_private 0
J login sebres
J priority 5\sMedium
J private_contact 50e9528765c18296566374b3fde2df942c394efd
J resolution None
J severity Severe
J status Open
J submitter sebres
J subsystem 21.\s[namespace]
J title Invocation\sof\simported\snested\scommand\sis\saffected\sby\srecursionlimit\sand\shas\sO(n)\sinstead\sof\sO(1)
J type Bug
K 0b3595a8191076b07b0603ae745d0c7c1a849666
U sebres
Z 6a0d9809abe00846c4280533af344051