Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: c473beecdb6be6f97a18f92a66bd060fe8273f355bd62b1210bb738cf4b0e955
Ticket: 3c6e47363e95219c386efcf066596f4472c5eff4
Performance degradation by compiled "lappend" command (compared to 8.5)
User & Date: sebres on 2020-07-15 17:50:03
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    Today I considered totally weird behavior testing some code (initially written for 8.5) in 8.6...
    Since I know the inner architecture of tcl-lists, I always thought that better is organize FIFO as LILO (because insert/removal of 0th element is very expensive operation on large lists), so showed also the practice all the time.
    
    But it is not correct for 8.6, see:
    <pre><code>
    proc test_fifo {l} { timerate {
      set l [linsert $l [set l 0] x]; set l [lreplace $l [set l 0] 0]
    } }
    proc test_lilo {l} { timerate {
      lappend l x; set l [lreplace $l [set l end] end]
    } }
     
    set c 1000
    while {$c <= 1e6} {
      puts "** $c **"
      puts fifo:\t[test_fifo [lrepeat $c a]]
      puts lilo:\t[test_lilo [lrepeat $c a]]
      set c [expr {$c * 10}]
    }
    </code></pre>
    <pre><code>
    # Results:
    
    # ----------------------------------
    # Tcl 8.5:
    # ----------------------------------
    
    ** 1000 **
    fifo:   0.815292 µs/# 1189045 # 1226554 #/sec 969.419 net-ms
    lilo:   0.319608 µs/# 2895810 # 3128836 #/sec 925.523 net-ms
    ** 10000 **
    fifo:   4.296829 µs/# 231345 # 232729 #/sec 994.050 net-ms
    lilo:   0.316483 µs/# 2922252 # 3159727 #/sec 924.843 net-ms
    ** 100000 **
    fifo:   44.1857 µs/# 22619 # 22631.7 #/sec 999.437 net-ms
    lilo:   0.316588 µs/# 2921358 # 3158682 #/sec 924.866 net-ms
    ** 1000000 **
    fifo:   519.944 µs/# 1924 # 1923.3 #/sec 1000.373 net-ms
    lilo:   0.317124 µs/# 2916790 # 3153344 #/sec 924.983 net-ms
    
    # ----------------------------------
    # Tcl 8.6:
    # ----------------------------------
    
    ** 1000 **
    fifo:   0.704807 µs/# 1338218 # 1418827 #/sec 943.186 net-ms
    lilo:   3.795696 µs/# 260543 # 263456 #/sec 988.942 net-ms
    ** 10000 **
    fifo:   4.236343 µs/# 233711 # 236052 #/sec 990.080 net-ms
    lilo:   35.7963 µs/# 27903 # 27935.9 #/sec 998.823 net-ms
    ** 100000 **
    fifo:   43.6455 µs/# 22890 # 22911.9 #/sec 999.046 net-ms
    lilo:   570.914 µs/# 1752 # 1751.6 #/sec 1000.241 net-ms
    ** 1000000 **
    fifo:   507.387 µs/# 1971 # 1970.9 #/sec 1000.059 net-ms
    lilo:   5640.94 µs/# 178 # 177.28 #/sec 1004.088 net-ms
    </code></pre>
    
    It affecting the lappend command, because replacing of <code>lappend l ...</code> with <code>set l [linsert $l [set l end] x]</code> solves the issue...
    
    Also it affects only compiled version, because replace of "timerate" with "time"  solving the issue too.
    
    In-between I found and fixed it (checking other corner cases) and will push my ultimate fix soon.
    
  5. foundin changed to: ">= 8.6"
  6. is_private changed to: "0"
  7. login: "sebres"
  8. priority changed to: "5 Medium"
  9. resolution changed to: "None"
  10. severity changed to: "Severe"
  11. status changed to: "Open"
  12. submitter changed to: "sebres"
  13. subsystem changed to: "47. Bytecode Compiler"
  14. title changed to:
    Performance degradation by compiled "lappend" command (compared to 8.5)
    
  15. type changed to: "Bug"