Skip to content
Tcl Source Code View Ticket
Login

View Ticket

lappend very slow in tcl 8.6

Closed / Duplicatedfccbeb623afe3f6db537614a008a0bc0cef4fdfCreated 12 years agoUpdated 12 years ago
Descriptionplain2014-08-19 16:09:26
The following snippet of code takes about 30 seconds in Tcl 8.6, but runs in well under a second in Tcl 8.5. The problem is something to do with the upvar, and with the fact that "lappend" appends two elements at once -- if you replace the call with two "lappend"s of one element each, it runs fast.
=============================
proc ArrayGetSorted {arrayPtr} {
    set result {}
    upvar 1 $arrayPtr arrayName
    set nameList [array names arrayName]
    puts "Start [clock seconds]"
    foreach name $nameList {
        lappend result $name $arrayName($name)
    }
    puts "Done [clock seconds]"
    return $result
}

for {set n 0} {$n < 40000} {incr n} {
    set arr([list top [expr rand()] [expr rand()]]) data
}
ArrayGetSorted arr
=============================
akuplain2014-08-19 16:52:15
The lappend issue is a duplicate of a bug which got recently fixed.

Hm. ... There is [1332fc7df2]; which is still open.

Found it, the issue was [b43f2b49f7]. The fix for that should be in the 8.5.16 release candidates, so you should be able to test if that fixes your issue.

Assigning to dkf to say more.
akuplain2014-08-19 16:54:01
The relevant checkin having the fix is
  [17150b71d2419a4db61140f860b58f7564be8ec9]
of Jun 18.
anonymous (claiming to be jal_frezie)plain2014-08-19 17:09:00
So, it will be fixed in Tcl 8.6.2 ?
akuplain2014-08-19 17:24:42
My mention of 8.5.16 was a typo. My apologies. I meant 8.6.2.
The current RC archives can be found at
     ftp://ftp.tcl.tk/pub/tcl/tcl8_6/
dkfwiki2014-08-28 09:13:17

This was a bug in the lappend compiler, [b43f2b49f7], which was generating code that didn't handle refcounts well in 8.6.1; the fact that using two simple lappends was a workaround was a pretty strong indicator of exactly that bug. Already fixed in 8.6.2.

Log in (anonymous is fine) to add a comment.