Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: e6c433289d93615e02f35a384f33b70bc207c47c
Ticket: 1890831fffffffffffffffffffffffffffffffff
Lrange cleanup and in-place optimization
User & Date: ferrieux on 2008-02-10 23:30:16
Changes

  1. assignee changed to: "dkf"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    The attached patch against 8.5.1 is a cleanup of the [lrange] implementation, including:
    
     - use of T_LOL to stick to the style of other list ops, instead of a complex and unique anti-shimmering share-intrep mechanism dedicated to a rare and already fast case [lrange $x $x $x].
    
     - flattening of if-return's to stick to the style of other list ops, improving readability.
    
     - detection of unshared case to operate in-place, by calling twice Tcl_ListObjReplace (in correct order).
    
    The first two points are just a matter of style, but allow for the third, which is a pretty significant optimization. Measurements on a 100-million list [lrepeat 100000000 1]:
    
     [lrange ... 1 end] in-place gives a 3x speedup
     [lrange ... 0 end-1] in-place gives a 24000x speedup
    
    -Alex
    
    
    % set l [lrepeat 100000000 1];llength $l
    100000000
    % time {set l [lrange $l 1 end];llength $l}
    814663 microseconds per iteration
    % proc K { x y } {set x}
    % time {set l [lrange [K $l [unset l]] 1 end];llength $l}
    272517 microseconds per iteration
    
    % set l [lrepeat 100000000 1];llength $l
    100000000
    % time {set l [lrange $l 0 end-1];llength $l}
    815985 microseconds per iteration
    % set l [lrepeat 100000000 1];llength $l
    100000000
    % time {set l [lrange [K $l [unset l]] 0 end-1];llength $l}
    34 microseconds per iteration
    
  4. foundin changed to: "None"
  5. is_private changed to: "0"
  6. priority changed to: "5 Medium"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "ferrieux"
  10. subsystem changed to: "17. Commands I-L"
  11. title changed to: "Lrange cleanup and in-place optimization"
  12. type changed to: "Patch"