Overview
| Artifact ID: | e9675b8513b2c95d9487a7683ffa432675dd5b645582f112c0b8377a22fa1df3 |
|---|---|
| Ticket: | 6811a0081940b76c438c22c55d1d3ec7ddf622d1
lsearch performance degradation on Tcl 8.6.11 release |
| User & Date: | anonymous on 2024-03-19 21:31:16 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-plain"
- comment changed to:
We have noticed certain situations where lsearch is much slower (4x or so? but depends on the size of the list) after going to Tcl 8.6.11. Specifically, it affects long lists with big strings that are similar to the search key. I did a fossil bisect and found this checkin on the 8.6 branch: 26e57ca1486e497b comment: More usage of TclUtfToUCS4(), so we can use the whole Unicode range better in TCL_UTF_MAX>3 builds. (user: jan.nijtmans) Here is a script that will reproduce the issue: http://paste.tclers.tk/5929 (script also included below) The issue can be worked around by using -exact. Perhaps there is an optimization opportunity? We aren't searching for any sort of glob pattern, so perhaps, for big lists, the search item could be examined for any glob characters? package require fileutil # Benchmark showing the impact on lsearch in Tcl 8.6.11 # # $ fossil info 26e57ca1486e497b # hash: 26e57ca1486e497b32e75a074c0ee81b62beefb8 2020-05-05 16:00:06 UTC # parent: 5d38a6b3c64572f808163ae7656333fea1e478a7 2020-05-05 15:56:14 UTC # child: b275de7c6434b50adf9f27ff24d01bd972efa624 2020-05-06 08:15:49 UTC # merged-into: b07935f03d33d1bdfb89a4b13f1fee914d78080d 2020-05-05 16:20:24 UTC # tags: core-8-6-branch # comment: More usage of TclUtfToUCS4(), so we can use the whole Unicode range better in TCL_UTF_MAX>3 builds. (user: jan.nijtmans) # # $ /usr/local/tcl8.6.11/bin/tclsh8.6 lbench.tcl # stringlist has 5000 items. # lsearch returned -1 took 2297 microseconds. # lsearch -exact returned -1 took 23 microseconds. # $ /usr/local/tcl8.6.10/bin/tclsh8.6 lbench.tcl # stringlist has 5000 items. # lsearch returned -1 took 512 microseconds. # lsearch -exact returned -1 took 24 microseconds. # # set alphabet [ list X M R 0 1 2 3 4 5 6 7 8 9 / ] # based on suchenwi's random string generator from the Tcl Wiki: proc lpick L {lindex $L [expr {int(rand()*[llength $L])}]} proc randomlyPicked { length {chars { X 0 1 2 3 4 5 6 7 8 9 / }} } { for {set i 0} {$i<$length} {incr i} {append res [lpick $chars]} return $res } set stringlist [ list ] # Generate some repetitive random strings # Start all strings with a common prefix set string_prefix "X14/X33/X5/X1848/X1/X3/X1/X1/X1/X1/X8/X49/X34" set numstrings 5000 for { set n 0 } { $n < $numstrings } { incr n } { set random_length [ expr { 5 + int(rand()*25) } ] set new_string "$string_prefix/[ randomlyPicked $random_length ]" lappend stringlist $new_string } # Search for a unique string that also has the same common prefix set search_for "$string_prefix/M0" puts "stringlist has [ llength $stringlist ] items." set timer [ clock microseconds ] set finder [ lsearch $stringlist $search_for ] puts "lsearch returned $finder took [ expr { [ clock microseconds ] - $timer } ] microseconds." set timer [ clock microseconds ] set finder [ lsearch -exact $stringlist $search_for ] puts "lsearch -exact returned $finder took [ expr { [ clock microseconds ] - $timer } ] microseconds." - foundin changed to: "8.6.11"
- is_private changed to: "0"
- login: "anonymous"
- priority changed to: "5 Medium"
- private_contact changed to: "084881249f6efe07e05d28fe9007e25c423f48c1"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "anonymous"
- subsystem changed to: "17. Commands I-L"
- title changed to:
lsearch performance degradation on Tcl 8.6.11 release
- type changed to: "Bug"