<i>Namespace import can cause quadratic big-O and affects all siblings of same original command</i>.
by
.
D 2025-03-27T13:53:45.965
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment <code>[namespace\simport]</code>\slooks\sto\sbe\saffected\sby\squadratic\sbig-O...\s\r\nEvery\sNS,\sOO-context,\setc\simporting\sthe\scommand\scauses\sthat\sit's\sdeletion\scosts\s<code>O(n**2)*m</code>,\swhere\s<code>n<code>\s-\snumber\sof\simports\sfor\soriginal\scommand,\sand\s<code>m</code>\s-\snumber\sof\ssuch\simported\scommands\sin\sNS/OO/etc.\r\n\r\nPoC:\r\n<code><pre>\r\n\s\snamespace\seval\sA\s{\sproc\sc1\s{}\s{};\sproc\sc2\s{}\s{};\sproc\sc3\s{}\s{};\snamespace\sexport\s*\s}\r\n\s\sproc\screate\s{ns}\s{\snamespace\seval\s$ns\s{\snamespace\simport\s::A::*\s}\s}\r\n\s\sforeach\scount\s{100\s1000\s10000\s100000}\s{\r\n\s\s\s\sputs\s"===\s$count\s==="\r\n\s\s\s\sset\si\s0;\sputs\s[timerate\s{\screate\s::B[incr\si];\s}\s1000\s$count]\r\n\s\s\s\sset\si\s0;\sputs\s[timerate\s{\snamespace\sdelete\s::B[incr\si];\s}\s1000\s$count]\r\n\s\s}\r\n</pre></code>\r\nresult:\r\n<code><pre>\r\n\s\s===\s100\s===\r\n\s\s26.0500\sµs/#\s100\s#\s38387.7\s#/sec\s2.605\snet-ms\r\n\s\s2.540000\sµs/#\s100\s#\s393700\s#/sec\s0.254\snet-ms\r\n\s\s===\s1000\s===\r\n\s\s13.8020\sµs/#\s1000\s#\s72453.3\s#/sec\s13.802\snet-ms\r\n\s\s9.236000\sµs/#\s1000\s#\s108271\s#/sec\s9.236\snet-ms\r\n\s\s===\s10000\s===\r\n\s\s11.0121\sµs/#\s10000\s#\s90809.2\s#/sec\s110.121\snet-ms\r\n\s\s285.814\sµs/#\s3498\s#\s3498.8\s#/sec\s999.776\snet-ms\r\n\s\s===\s100000\s===\r\n\s\s10.9604\sµs/#\s90967\s#\s91237.9\s#/sec\s997.031\snet-ms\r\n\s\s14274.5\sµs/#\s70\s#\s70.055\s#/sec\s999.212\snet-ms\r\n</pre></code>\r\n(the\slast\stwo\sare\snot\sachieved\sthe\swhole\sset\s(would\stake\sa\ssmall\seternity\sfor\sthe\slast),\sit\shas\smastered\sonly\s70\sdeletions\sin\sa\ssecond,\swhere\son\sprevious\sorder\sof\smagnitude\sit\swas\s3.5k\sin\sa\ssecond).\r\n\r\nCausation\sis\s<code>ImportRef\s*importRefPtr</code>\sin\s<code>Command</code>\sstructure,\swhat\sis\sunidirectional\slist.\r\nMoreover\sit's\sexistence\sis\snot\sjustified\sat\sall\s-\sthis\scauses\sdrastic\sperformance\simpacts\sin\sany\scases,\sand\sbasically\sneeded\sonly\sto\spass\snamespace-56.6\s(deletion\sof\soriginal\scommand\sshall\scause\sthe\sinvocation\sof\sdeletion-traces\son\simported\scommands).\r\nThis\s(if\sneeded\sat\sall)\scan\sbe\sachieved\swith\sother\sway\swithout\sthat\slist.
J foundin any
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 -\sNew\sBuiltin\sCommands
J title Namespace\simport\scan\scause\squadratic\sbig-O\sand\saffects\sall\ssiblings\sof\ssame\soriginal\scommand
J type Bug
K 62dafd9c53882dc27f4bbd68ad5b2160f06129ff
U sebres
Z a163f4a51d51f919becd138453cdbddf