Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 6e2bd65927e67a6643693b6dc62b5c770299d58a
Ticket: 2873596fffffffffffffffffffffffffffffffff
Slowness in passing data through interp eval
User & Date: dgp on 2014-10-09 16:16:07
Changes

  1. closedate changed to: "2456940.17786013"
  2. closer changed to: "dgp"
  3. 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
    
  4. login: "dgp"
  5. mimetype: "text/plain"
  6. resolution changed to: "Out of Date"
  7. severity changed to: "Minor"
  8. status changed to: "Closed"