Artifacts Associated With Ticket 2873596fffffffff
Ticket change [44d8ad26db] (rid 116772) by apnadkarni on 2009-10-06 17:39:20:
- assignee initialized to: "hobbs"
- cmimetype initialized to: "text/plain"
- comment initialized to:
I want to process data received over the network in a safe interpreter (although for the purposes of this question, the safe-ness is irrelevant). Roughly speaking, I invoke the safe interpreter as safeinterp eval [list process_request $received_data] What I've found is that invoking the slave interpreter in this manner is slower than processing in the same interpreter by two orders of magnitude or more. Here is a tkcon session simulating the issue: (woof) 51 % interp create ip ip (woof) 52 % ip eval {proc slaveproc arg {}} (woof) 53 % string length [set s [string repeat x 100000]] 100000 (woof) 54 % time {ip eval [list slaveproc $s]} 10 3335.4 microseconds per iteration So roughly, 3.3ms to pass 100K into an empty proc in the slave. By comparison, passing it to a proc in the same interp (using eval for consistency) (woof) 55 % proc masterproc arg {} (woof) 56 % time {eval [list masterproc $s]} 10 9.3 microseconds per iteration So use of a slave interpreter in this fashion is MUCH slower. Timestamping the C code, the slowdown with the slave interp seems to happen because of shimmering in SlaveEval (the internal rep for the list is thrown away and converted to a string and then converted back in the slave). Workaround - Alexander Ferrieux on tcl-core pointed out a workaround. To quote him - ---- While I admit I don't fully understand this necessity, it turns out the multiple-argument code path doesn't have the limitation, since it directly calls Tcl_ConcatObj on its list of arguments, and it is well known that TCO is optimized for all-pure-list arguments (dating back to Paul Duffin's work on Concat objects IIRC). Hence one can derive a script-level idiom guaranteeing a shimmerless path: ip eval [list slaveproc] [list $s] ----- I also tested with 8.5.2. It is equally slow, and what's more Alexander's workaround does not work there (it's still slow), presumably because Tcl_ConcatObj is not optimized in 8.5.2 (conjecture) /Ashok - foundin initialized to: "obsolete: 8.6b1.1"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "apnadkarni"
- subsystem initialized to: "20. [interp]"
- title initialized to: "Slowness in passing data through interp eval"
- type initialized to: "Bug"
Ticket change [2a5d62e295] (rid 118554) by dgp on 2009-10-07 00:48:25:
- icomment:
do you have any tests without the corruption imposed by [string length] ?
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [b60a4ebe7c] (rid 125356) by dgp on 2009-10-07 00:51:36:
- icomment:
this is fixed on the HEAD (for 8.6b2): % interp create ip ip % ip eval {proc slaveproc arg {}} % string length [set s [string repeat x 100000]] 100000 % time {ip eval [list slaveproc $s]} 10 13.7 microseconds per iteration % proc masterproc arg {} % time {eval [list masterproc $s]} 10 11.1 microseconds per iteration - login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [4be467f838] (rid 126780) by dgp on 2009-10-07 00:56:49:
- icomment:
bug is also not present in the 8.5.7 release: % interp create ip ip % ip eval {proc slaveproc arg {}} % string length [set s [string repeat x 100000]] 100000 % time {ip eval [list slaveproc $s]} 10 12.2 microseconds per iteration % proc masterproc arg {} % time {eval [list masterproc $s]} 10 9.6 microseconds per iteration leaving open just for sake of 8.4.20. - login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [1402b3390e] (rid 124319) by dgp on 2009-10-07 00:56:50:
- priority changed to: "3 Low"
Ticket change [ba23534458] (rid 129268) by dgp on 2009-10-08 03:54:47:
- assignee changed to: "dgp"
Ticket change [6e2bd65927] (rid 140213) by dgp on 2014-10-09 16:16:07:
- closedate changed to: "2456940.17786013"
- closer changed to: "dgp"
- comment changed to:
I want to process data received over the network in a safe interpreter (although for the purposes of this question, the safe-ness is irrelevant). Roughly speaking, I invoke the safe interpreter as safeinterp eval [list process_request $received_data] What I've found is that invoking the slave interpreter in this manner is slower than processing in the same interpreter by two orders of magnitude or more. Here is a tkcon session simulating the issue: (woof) 51 % interp create ip ip (woof) 52 % ip eval {proc slaveproc arg {}} (woof) 53 % string length [set s [string repeat x 100000]] 100000 (woof) 54 % time {ip eval [list slaveproc $s]} 10 3335.4 microseconds per iteration So roughly, 3.3ms to pass 100K into an empty proc in the slave. By comparison, passing it to a proc in the same interp (using eval for consistency) (woof) 55 % proc masterproc arg {} (woof) 56 % time {eval [list masterproc $s]} 10 9.3 microseconds per iteration So use of a slave interpreter in this fashion is MUCH slower. Timestamping the C code, the slowdown with the slave interp seems to happen because of shimmering in SlaveEval (the internal rep for the list is thrown away and converted to a string and then converted back in the slave). Workaround - Alexander Ferrieux on tcl-core pointed out a workaround. To quote him - ---- While I admit I don't fully understand this necessity, it turns out the multiple-argument code path doesn't have the limitation, since it directly calls Tcl_ConcatObj on its list of arguments, and it is well known that TCO is optimized for all-pure-list arguments (dating back to Paul Duffin's work on Concat objects IIRC). Hence one can derive a script-level idiom guaranteeing a shimmerless path: ip eval [list slaveproc] [list $s] ----- I also tested with 8.5.2. It is equally slow, and what's more Alexander's workaround does not work there (it's still slow), presumably because Tcl_ConcatObj is not optimized in 8.5.2 (conjecture) /Ashok - login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Out of Date"
- severity changed to: "Minor"
- status changed to: "Closed"