Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Performance degradation by compiled "lappend" command (compared to 8.5)

Closed / Fixed3c6e47363e95219c386efcf066596f4472c5eff4Created 6 years agoUpdated 6 years ago
Descriptionwiki2020-07-15 17:50:03
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:


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}] }


# 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

It affecting the lappend command, because replacing of lappend l ... with set l [linsert $l [set l end] x] 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.

Referenced by1
  • 1947d9b440closes [3c6e47363e]: missing de-duplication mechanism for nested TEBC starting from scratch (e. g. nested compiled blocks enclosed in parent cycle), so reset interp's result to avoid possible duplications of large objects by first commands like lappend, append, etc check-in2020-07-15 20:06:07
sebres Ticket [3c6e47363e]: 3 changes [History diff]2020-07-15 17:50:17
sebreswiki2020-07-15 19:17:40

No - there are too many corner cases.

Something is inefficient by de-duplication handling in TEBCresume (initially provided for [781585], [804681]). But rather it is wrong somewhere, because I see refCount growing every first time it enter test_lilo (where it should remain unchanged), so it could also leak at some point (must check).

WiP.

sebreswiki2020-07-15 20:07:25

Should be fixed now in [1947d9b440].

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