<i>lseq - duplicative expr eval, bottleneck by usage of operators, inconstistent handling of indices (int vs. double vs. error), etc</i>.
by
.
D 2024-06-11T23:59:30.126
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment In\san\sattempt\sto\sfix\sthe\sbottleneck,\sI\sfound\sthat\scommand\s<code>lseq</code>\sis\sa\sbit\sraw\sand\shas\sseveral\sbugs\sand\sinconsistencies.\r\n\r\n1.\sDuplicative\sevaluation\sof\sexpressions,\swhat\snot\sonly\sinefficient,\sbut\salso\sbuggy\sand\shardly\sdeterministic\s(if\ssomeone\smakes\sstorable\soperations\sinside,\slike\s<code>incr</code>).\sSo\severy\sexpression\swill\sbe\sinvoked\stwice,\showever,\sstill\sworse,\sthe\svalue\smay\sbe\sthereby\sfrom\sthe\sfirst\sor\sthe\ssecond\seval\sdepending\son\sits\sresult\stype\s(by\sint\swins\s1st\seval,\sby\sdouble\swins\sthe\s2nd\seval).\r\nFor\sexample\s(red\s-\scurrent\sstate,\sgreen\s-\sexpected)\r\n<code><pre\sstyle="padding-left:2rem;">\r\n\s\s%\sset\si\s0;\slist\s[lseq\s{[puts\s"just\sa\strace,\si:$i";\sincr\si]-1}\s{[incr\si]}]\si:$i\r\n\s\sjust\sa\strace,\si:0\r\n<b\sstyle="color:red;">-\sjust\sa\strace,\si:1</b>\r\n<b\sstyle="color:red;">-\s{0\s1\s2\s3}\si:4</b>\r\n<b\sstyle="color:green;">+\s{0\s1\s2}\si:2</b>\r\n \r\n\s\s%\sset\si\s0;\slist\s[lseq\s{[puts\s"just\sa\strace,\si:$i";\sincr\si]-1}\s{[incr\si]+0.1}]\si:$i\r\n\s\sjust\sa\strace,\si:0\r\n<b\sstyle="color:red;">-\sjust\sa\strace,\si:1</b>\r\n<b\sstyle="color:red;">-\s{0.0\s1.0\s2.0\s3.0\s4.0}\si:4</b>\r\n<b\sstyle="color:green;">+\s{0.0\s1.0\s2.0}\si:2</b>\r\n</pre></code>\r\n\r\n2.\sUsage\sof\slseq-operators\shas\sa\sbottleneck\sby\ssaving\sthe\sresult\sand\sattempt\sto\seval\sit\sas\sexpression\s(due\sto\swrong\sorder\sof\schecks).\sWhat\scauses\salmost\s40x\s\s-50x\sgrowth\sof\sthe\sexecution\stime\sper\soperator.\sFor\sexample:\r\n<code><pre\sstyle="padding-left:2rem;">\r\n%\stimerate\s{lseq\s1\s10}\r\n<span\sstyle="color:green;">0.237085\sµs/#\s3588607\s#\s4217895\s#/sec\s850.805\snet-ms</span>\r\n%\stimerate\s{lseq\s1\sto\s10}\r\n<span\sstyle="color:red;">9.000940\sµs/#\s110589\s#\s111099\s#/sec\s995.405\snet-ms</span>\r\n%\stimerate\s{lseq\s1\s10\s2}\r\n<span\sstyle="color:green;">0.248337\sµs/#\s3458008\s#\s4026792\s#/sec\s858.750\snet-ms</span>\r\n%\stimerate\s{lseq\s1\sto\s10\sby\s2}\r\n<span\sstyle="color:red;">18.5890\sµs/#\s53678\s#\s53795.4\s#/sec\s997.818\snet-ms</span>\r\n</pre></code>\r\n\r\n3.\sInconsistent\shanding\sby\sdouble\s(round-able\sto\sinteger\sdoubles\ssometimes\scauses\sinteger\sseries,\ssometimes\sdouble\sseries\sand\ssometimes,\smostly\sby\scount,\san\serror\s'<code>expected\sinteger\sbut\sgot\s"3.0"</code>'\s(for\sexample\sfor\s<code>lseq\s3.0</code>)\r\n\r\n4.\sA\sseries\swith\sfew\selements\sbut\sbig-integers\scan\scause\sa\smax\slist\slength\serror.\sEither\sit'd\sneed\sdifferent\serror\smessage,\sor\sit\smust\sbe\sfixed\sfor\sbig-ints\s(support\sthem).\sFor\sexample\s3\selements\sseries:\r\n<code><pre\sstyle="padding-left:2rem;">\r\n%\slseq\s0x[string\srepeat\sf\s14]0\s..\s0x[string\srepeat\sf\s14]2\r\n1152921504606846960\s1152921504606846961\s1152921504606846962\r\n%\slseq\s0x[string\srepeat\sf\s15]0\s..\s0x[string\srepeat\sf\s15]2\r\n<span\sstyle="color:red;">max\slength\sof\sa\sTcl\slist\sexceeded</span>\r\n</pre></code>\r\n\r\n5.\sIf\slseq\ssupports\sexpressions,\sit\smust\sdo\sthat\sproperly.\sFor\sinstance\sI\sexpect\sthe\ssame\serror\shere\s(and\sdefinitely\snot\s"bad\soperation"\sin\sthe\s2nd\scase):\r\n<code><pre\sstyle="padding-left:2rem;">\r\n%\slseq\s[expr\s{$i/0}]\r\ndivide\sby\szero\r\n%\slseq\s{$i/0}\r\n<span\sstyle="color:red;">bad\soperation\s"$i/0":\smust\sbe\s..,\sto,\scount,\sor\sby</span>\r\n</pre></code>\r\n\r\n6.\sDuring\smy\sperformance\stests\sI\ssaw\ssome\sleaks...\sno\sidea\sexactly\swhere\sand\sdon't\sintend\sto\sinvest\sthe\stime\shere,\sbecause\sas\sI\swas\sready\swith\smy\scode\sreview\sI\scannot\sreproduce\sthe\sleaks\sanymore.
J foundin 8.7+
J is_private 0
J login sebres
J priority 5\sMedium
J private_contact 50e9528765c18296566374b3fde2df942c394efd
J resolution None
J severity Minor
J status Open
J submitter sebres
J subsystem 17.\sCommands\sI-L
J title lseq\s-\sduplicative\sexpr\seval,\sbottleneck\sby\susage\sof\soperators,\sinconstistent\shandling\sof\sindices\s(int\svs.\sdouble\svs.\serror),\setc
J type Bug
K f05f5ef759c1f7f93903fd873250a4c76147c4b2
U sebres
Z bb84e7095bef2671692149e29b2a60f8