Skip to content
Tcl Source Code Artifact [90cb565845]
Login

Artifact [90cb565845]

Artifact 90cb565845bcae3b1dcb17e619ac8cc4d4db7572:

Ticket change [90cb565845] - New ticket [fdfbd5e10fefdb60|fdfbd5e10f] <i>Event, Notifier and Timer optimizations / implementation of TIP #302</i>. by sebres on 2017-07-10 12:17:30.
D 2017-07-10T12:17:30.969
J assignee nobody
J closer nobody
J cmimetype text/html
J comment <h3>Implementation:</h3>\r\n&nbsp;\s-\s<a\shref="/tcl/timeline?r=sebres-8-6-event-perf-branch&nd&n=200">[sebres-8-6-event-perf-branch]</a>\s-\s8.6\sbased\sbranch<br/>\r\n&nbsp;\s-\s<a\shref="/tcl/timeline?r=sebres-8-5-event-perf-branch&nd&n=200">[sebres-8-5-event-perf-branch]</a>\s-\s8.5\sbased\sbranch\r\n\r\n<p>First\simplemented\s(squashed\srebased\sand\scherry-picked)\sfor\s8.5-branch,\sbecause\sI\smade\sit\sbasically\sfor\sfork\sof\sthis\sbranch\s(it\swas\sjust\seasy\sas\sdirect\sfor\s8.6).</p>\r\n\r\n<h3>Contains:</h3>\r\n<ul>\r\n<li>massive\sperformance\soptimization\sof\sevent-driven\shandling\s(test-cases\sincluded),\sso\scan\sbe\ssee\sas\spart\sof\s<a\shref="https://github.com/flightaware/Tcl-bounties/issues/21"\sclass="issue-link\sjs-issue-link"\sdata-url="https://github.com/flightaware/Tcl-bounties/issues/21"\sdata-id="197943681"\sdata-error-text="Failed\sto\sload\sissue\stitle"\sdata-permission-text="Issue\stitle\sis\sprivate">flightaware/Tcl-bounties#21</a>;</li>\r\n<li>whole\sevent-driven\sfunctionality\sis\sup\sto\s1000-times\sfaster\snow\s(especially\sby\slarge\sevent\sresp.\stimer\slists,\sbut\salso\sbasic\smulti-threaded\sevent-related\sthings\slike\sasync-IO,\sreflected\schannels,\setc.);</li>\r\n<li>provided\smonotonic\stime\s(windows/unix);</li>\r\n<li>timer\sevents\sand\swait\sfacilities\sare\stime-jump\ssafe\sat\sall\s-\simplementation\sfor\s<a\shref="http://www.tcl.tk/cgi-bin/tct/tip/302.html">TIP\s#302</a>.</li>\r\n<li>full\sNRT-\sresp.\sRTS-capabilities\s(micro-\sresp.\snanoseconds\sprecise);</li>\r\n<li>implemented\swide-clicks\son\sunix\s(1\swide-click\s==\s0.001\smicroseconds\s(1\snanosecond)),\sso\smore\sprecise\snow\s(e.\sg.\sby\stime\smeasurement\setc.);</li>\r\n<li>windows\shigh-resolution\stime\srewritten\swithout\scalibration\sthread\snow\s(faster,\smore\srobust\sand\sprovides\sin\saddition\smonotonic\stime,\snot\saffected\sfrom\sthe\stime-jumps);</li>\r\n<li>implements\snew\ssub-command\s<code>after\sat</code>\sfor\sasync\strigger\sresp.\ssleep\susing\sabsolute\stime\s(in\sseconds),\sthat\salso\stime-jump\ssafe,\sand\sin\scontrary\sto\s<code>after\s$offs</code>\suses\sabsolute\sbased\stime\sas\sdue-time.<br>\r\n<code>after\sat\s[clock\sscan\s"16:00:00"]\s{do_it_in_1600}</code><br>\r\n<code>after\sat\s[clock\sscan\s"+1\sminute"];\s#\swait\sto\sthe\snext\sminute</code></li>\r\n<li>thus\sfully\simplements\s<a\shref="https://github.com/flightaware/Tcl-bounties/issues/2"\sclass="issue-link\sjs-issue-link"\sdata-url="https://github.com/flightaware/Tcl-bounties/issues/2"\sdata-id="190304010"\sdata-error-text="Failed\sto\sload\sissue\stitle"\sdata-permission-text="Issue\stitle\sis\sprivate">flightaware/Tcl-bounties#2</a></li>\r\n<li>timer-events\sdistinguish\snow\sbetween\srelative\stime-intervals\s(which\suse\smonotonic\sbased\stime)\sand\sabsolute\sdue-time\s(which\suses\sreal-time\sbase);</li>\r\n<li>ultimate\ssolution\s(resp.\sfix)\sfor\sticket\s<a\shref="http://core.tcl.tk/tcl/info/0520d17284500573d7c46aa88e0c6b4ebc9b6a02">0520d17284500573d7c46aa88e0c6b4ebc9b6a02</a></li>\r\n<li>handling\sround\sabout\sobjects\sreturned\sby\s<code>after</code>\s(and\ssome\sinternal\sinterfaces)\sare\smore\sfaster\snow,\sbecause\shold\sthe\stimer-event\sin\sthe\sinternal\srepresentation\sof\sobject,\sso\se.\sg.\s<code>after\sinfo</code>,\s<code>after\scancel</code>\setc\sdon't\sneed\sto\ssearch\san\sevent\sin\sevent-lists\sanymore\s(and\stherefore\sdon't\sblock\sthe\slist\swith\slock\sfor\sthe\slong\stime);</li>\r\n<li>event\s(Tcl_Event)\sprolongation\sfunctionality\s(setting\sof\s<code>event-&gt;proc</code>\sto\sthe\scallback\scauses\sreattach\sof\sthis\sevent\sto\send\sof\sthe\squeue,\sin\scontrary\sto\s<code>return\s0</code>,\swhich\sleaves\sthe\sevent\son\sthe\scurrent\sposition,\sand\sthus\scan\srepeat\sit\stoo\searly);</li>\r\n<li>timer\sprolongation\sfunctionality\s(ATM\sonly\sin\sC-API\sas\s<code>TclpProlongTimerEvent</code>,\scan\sbe\slater\sused\sas\snew\ssub-command\s<code>after\sprolong</code>);</li>\r\n<li>Bonus:\r\n<ul>\r\n<li>commands\s<code>vwait</code>\sand\s<code>update</code>\scan\scontrol\swhich\sevents\sshould\sbe\saccepted:<br>\r\n<code>update\s-timer</code><br>\r\n<code>update\s-noidle</code><br>\r\n<code>vwait\s-async\s-timer\sx</code></li>\r\n<li>commands\s<code>vwait</code>\scan\suse\soptional\stimeout:<br>\r\n<code>if\s{![vwait\s-timer\s10\stmrVar]}\scontinue;\s#\sdo\ssomething\sother\sresp.\stry\slater</code><br>\r\n<code>if\s{![vwait\s1000\sevVar]}\s{\serror\s"timeout\soccurred"\s}</code></li>\r\n<li>commands\s<code>vwait</code>\scan\swork\ssimilar\sto\s<code>update</code>,\swithout\swaiting\sfor\sevents\s(process\sonly\salready\soccurring\sevents):<br>\r\n<code>if\s{[info\sexists\sevVar]\s||\s[vwait\s-nowait\s10\sevVar]}\s{\sputs\s"event\salready\slaunched"\s}</code><br>\r\n<code>##\supdate\sand\scheck\swe\sare\sdone:</code><br>\r\n<code>while\s{![vwait\s-nowait\s0\sdone]}\s{\sdo\ssomething\sother\s}</code></li>\r\n<li>commands\s<code>after</code>\sand\s<code>vwait</code>\sare\smicrosecond\sprecise\snow\s(so\sNRT-capable,\salso\saccept\stime\sas\sdouble):<br>\r\n<code>after\s0.01\s[list\saccept\s$socket];\s#\sdo\sit\sin\s10\smicroseconds</code><br>\r\n<code>##\swait\s5\sµs\sfor\s"x"\sand\sif\snot\syet\sready,\s25\sµs\sfor\s"y":</code><br>\r\n<code>if\s{![vwait\s0.005\sx]}\s{vwait\s0.025\sy}</code></li>\r\n<li>new\sclock\ssub-command\s<code>clock\smonotonic</code>\sto\sprovide\smonotonic\stime\sat\stcl-level\salso;</li>\r\n<li>etc.\s(I'll\sprovide\sadditional\sinfo\slater).</li>\r\n</ul>\r\n</li>\r\n</ul>\r\n\r\n<h4>Summaries\sof\sthe\sperformance\stest-cases:</h4>\r\nSee\s<a\shref="https://github.com/sebres/tcl/pull/4#issuecomment-312252977">sebres/tcl#4\s(comment)</a>\sfor\sthe\sperformance\scomparision.
J foundin 8.5\s/\s8.6
J is_private 0
J login sebres
J priority 5\sMedium
J resolution None
J severity Minor
J status Open
J submitter sebres
J subsystem 02.\sEvent\sLoops
J title Event,\sNotifier\sand\sTimer\soptimizations\s/\simplementation\sof\sTIP\s#302
J type RFE
K fdfbd5e10fefdb605abf34f65535054c323d9394
U sebres
Z f636ffaaafb8fe5517b1c12619120877