Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 9754a0737a5413178415aab6330d85873ac58fa6214849642a18eb6a0235e144
Ticket: 6811a0081940b76c438c22c55d1d3ec7ddf622d1
lsearch performance degradation on Tcl 8.6.11 release
User & Date: sebres on 2024-03-20 15:51:29
Changes

  1. icomment:
    My few cents for the issue:
    
    1. it seems to affect <b>-glob</b> search (as its docu says "If option is omitted then it defaults to <b>-glob</b>"), so definitely affected by changes of <i>Tcl_StringCaseMatch</i> etc.
    
    2. The regression is also obvious with much simpler test, here as diff between current 8.6 from core-repo and 8.6.9 (no speed degradation), and it's as correctly estimated above indeed 4x slower:
    
    <code><pre style="padding-left:10pt">
      % timerate -calibrate {}
      % set str [join [lrepeat 12 "XXX"] /]; set l [lrepeat 5000 $str]; llength $l
      % proc test {} {global l str; timerate { lsearch $l $str/M }}; test
    - 2287.38 µs/# 438 # 437.18 #/sec 1001.874 net-ms
    + 546.060 µs/# 1832 # 1831.3 #/sec 1000.382 net-ms
      % proc test {} {global l str; timerate { lsearch -exact $l $str/M }}; test
    - 8.060231 µs/# 123457 # 124065 #/sec 995.092 net-ms
    + 8.104484 µs/# 122794 # 123388 #/sec 995.182 net-ms
    </pre></code>
    (as one can see, the second measurement with <b>lsearch -exact</b> is indeed not affected.)
    
    3. Viewing the found commit [26e57ca1486e497b], it is striking the usage of 
    <i>TclUtfToUCS4</i> instead of <i>TclUtfToUniChar</i> en masse. However <i>TclUtfToUniChar</i> was a macro (quasi inline function), where <i>TclUtfToUCS4</i> is an internal function (not even static, so wouldn't be inlined in -O2) and it also internally uses <i>Tcl_UtfToUniChar</i> in opposite to <i>TclUtfToUniChar</i> (with the same consequences), what can theoretically explain this 2x + 2x degradation.
    
    I'll try to fix it now.
    
  2. login: "sebres"
  3. mimetype: "text/x-fossil-wiki"