Tcl Source Code

View Ticket
Login
Ticket UUID: 1586292
Title: threaded build too slow?
Type: Bug Created on: 2006-10-28 16:00:13
Submitter: msofer Assigned to: msofer
Subsystem: 49. Threading Severity:
Priority: 5 Medium Last modified: 2008-07-13 09:20:23
Status: Closed Closed by: sf-robot
Resolution: Fixed Closed on: 2008-07-13 02:20:23
Version: obsolete: 8.5a6
Description:
For reasons that are not important here, I timed the
speed of proc and ensemble calls in current HEAD. The
threaded build is *much* slower (1.75x). 

The script at /tmp/test is

   proc a {x y} {set x 1}
   namespace ensemble create -command ::w -map {a a}
   # Just to make the timings stabilise accross runs
   # ... probably too much, but who cares
   time {a 1 2} 10000
   time {w a 1 2} 10000
   lappend res proc:[time {a 1 2} 10000]
   lappend res ense:[time {w a 1 2} 10000]
   lappend res [info patchlevel]
   puts [join $res \n]

Building with --disable-shared I get

   sh-3.1# ./tclsh /tmp/test
   proc:2.3583 microseconds per iteration
   ense:3.1632 microseconds per iteration
   8.5a6

and with --disable-shared --enable-threads

   sh-3.1# ./tclsh /tmp/test
   proc:4.1325 microseconds per iteration
   ense:5.8033 microseconds per iteration
   8.5a6
User Comments:
msofer added on 2006-10-28 23:21:36:
Logged In: YES 
user_id=148712

With ActiveTcl it is even slower (I imagine this is due to
the shared build, as not much optimisation has been done in
proc calls since then):
mig@ice:/home/CVS/tcl_SF_clean/unix$ tclsh /tmp/test
proc:5.4506 microseconds per iteration
ense:7.678 microseconds per iteration
8.5a4

% parray ::activestate::ActiveTcl
::activestate::ActiveTcl(arch)          = linux-ix86
::activestate::ActiveTcl(as,mode)       = normal
::activestate::ActiveTcl(build)         = 261540
::activestate::ActiveTcl(buildtime,fmt) = Sat Apr 15
01:24:58 AM PDT 2006
::activestate::ActiveTcl(buildtime,sec) = 1145089498
::activestate::ActiveTcl(maturity)      = beta-5
::activestate::ActiveTcl(product)       = ActiveTcl
::activestate::ActiveTcl(release)       = 8.5.0.0

msofer added on 2006-10-29 00:01:59:
Logged In: YES 
user_id=148712

Threaded build using glibc's malloc instead of Tcl's pooled
allocator it is even slower, so the problem is probably not
mainly with the allocator.

mig@ice:/home/CVS/tcl_SF_clean/unix$ ./tclsh /tmp/test
proc:4.4455 microseconds per iteration
ense:6.0062 microseconds per iteration
8.5a6

msofer added on 2006-10-29 00:08:40:
Logged In: YES 
user_id=148712

Disabling the call to TclpCheckStackSpace in TclInterpReady
makes threaded builds quite a bit faster:

mig@ice:/home/CVS/tcl_SF_clean/unix$ ./tclsh /tmp/test
proc:3.0335 microseconds per iteration
ense:4.5398 microseconds per iteration
8.5a6

msofer added on 2006-10-29 01:33:23:
Logged In: YES 
user_id=148712

Hmmm ... my timings are very erratic. Several runs of the
same threaded build, right after each other:

mig@ice:/home/CVS/tcl_SF_clean/unix$ ./tclsh /tmp/test
proc:4.48498 microseconds per iteration
ense:6.03318 microseconds per iteration
8.5a6
mig@ice:/home/CVS/tcl_SF_clean/unix$ ./tclsh /tmp/test
proc:3.90434 microseconds per iteration
ense:5.86458 microseconds per iteration
8.5a6
mig@ice:/home/CVS/tcl_SF_clean/unix$ ./tclsh /tmp/test
proc:4.10458 microseconds per iteration
ense:5.98978 microseconds per iteration
8.5a6
mig@ice:/home/CVS/tcl_SF_clean/unix$ ./tclsh /tmp/test
proc:2.1277 microseconds per iteration
ense:2.93122 microseconds per iteration
8.5a6
mig@ice:/home/CVS/tcl_SF_clean/unix$ ./tclsh /tmp/test
proc:4.39368 microseconds per iteration
ense:6.04074 microseconds per iteration
8.5a6

mistachkin added on 2006-10-29 09:37:48:
Logged In: YES 
user_id=113501


It's probably slower because the previous
TclpCheckStackSpace was a no-op on Unix.

msofer added on 2008-01-12 20:13:20:
Logged In: YES 
user_id=148712
Originator: YES

Still an issue? If it was due to stack checking it should have been fixed by the new algorithm.

hobbs added on 2008-01-14 07:31:12:
Logged In: YES 
user_id=72656
Originator: NO

Running the head over tclbench with a threaded and non-threaded build (yes and no below), it is slower (mutexes actually kicking in), but not as serious as the above numbers show.

TCL_INTERP: 1:8.5.1b1 2:8.5.1b1
STARTED 2008-01-13 16:19:59 (runbench.tcl v1.21)
Benchmark 1:8.5.1b1 /home/jeffh/install/linux-ix86/bin/tclsh8.5t-no
abbccdeeeffghkllmmmmnpprrssstuvw 00:02:18 elapsed
131271 milliseconds
Benchmark 2:8.5.1b1 /home/jeffh/install/linux-ix86/bin/tclsh8.5t-yes
abbccdeeeffghkllmmmmnpprrssstuvw 00:02:43 elapsed
157038 milliseconds

sf-robot added on 2008-07-13 09:20:23:
Logged In: YES 
user_id=1312539
Originator: NO

This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).