Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: eb5c5e8f3b224c6a59c8245be3f589c129b0939d684d86c77b8555d0d9cba3c2
Ticket: 28cc67a606a7ab771af4c7b542b34ec1a377edc7
array set from dict: set values multi times on the same array is slower with Tcl9.0.
User & Date: sebres on 2024-04-16 14:51:37
Changes

  1. icomment:
    It is only affected if the value is set from dict.
    Basically as already correct assumed, it is not <i>array set</i> - it is foreach over dict content (foreach_start/foreach_step instructions compiled internally) that cause performance regression there.
    
    Here is an example without <i>array set</i>, that shows the same regression with 9.0 (also <i>llength $v</i> does it):
    
    ```
    proc SimplePERM {{asdict 1}} {
        if {$asdict} {
            set permmod [dict create]
            for {set i 0} {$i < 512} {incr i} {
                dict set permmod $i 1       
            }
        } else {
            set permmod {}
            for {set i 0} {$i < 512} {incr i} {
                lappend permmod $i 1
            }
        }
        return $permmod
    }
    
    proc generateData {{n 10000} {asdict 1}} {
        array set val {}
        set v [SimplePERM $asdict]
        for {set i 0} {$i < $n} {incr i} {
            # array set val $v
            # llength $v
            foreach {en ev} $v {}
        }
    }
    
    generateData 2000; # warm-up
    puts [timerate {generateData 1000 1} 10000 1]
    puts [timerate {generateData 2000 1} 10000 1]
    
    generateData 2000 0; # warm-up
    puts [timerate {generateData 1000 0} 10000 1]
    puts [timerate {generateData 2000 0} 10000 1]
    ```
    
  2. login: "sebres"
  3. mimetype: "text/x-markdown"
  4. title changed to:
    array set from dict: set values multi times on the same array is slower with Tcl9.0.