Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2014-10-09
16:16 • Closed ticket [2873596fff]: Slowness in passing data through interp eval plu... artifact: 6e2bd65927 user: dgp
2009-10-08
03:54 • Ticket [2873596fff]: 1 change artifact: ba23534458 user: dgp
2009-10-07
00:56 • Ticket [2873596fff]: 1 change artifact: 1402b3390e user: dgp
00:56 • Ticket [2873596fff]: 4 changes artifact: 4be467f838 user: dgp
00:51 • Ticket [2873596fff]: 4 changes artifact: b60a4ebe7c user: dgp
00:48 • Ticket [2873596fff]: 4 changes artifact: 2a5d62e295 user: dgp
2009-10-06
17:39 • New ticket [2873596fff]. artifact: 44d8ad26db user: apnadkarni

Slowness in passing data through interp eval

Closed / Out of Date2873596fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 12 years ago
Descriptionplain2009-10-06 17:39:20
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
dgpplain2009-10-07 00:48:25
do you have any tests without the
corruption imposed by [string length] ?
dgpplain2009-10-07 00:51:36
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
dgpplain2009-10-07 00:56:49
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.
dgp Ticket [2873596fff]: 1 change [History diff]2009-10-07 00:56:50
dgp Ticket [2873596fff]: 1 change [History diff]2009-10-08 03:54:47
dgp Closed ticket [2873596fff]. [History diff]2014-10-09 16:16:07
Log in (anonymous is fine) to add a comment.