Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: eed28b98f0e364094d88236bbb9436551ba39cf0c70d3731f9796ab7ada87722
Ticket: b3628609ad73a105f0e51435e0e0ac5b8205fad7
concatenating strings is broken when the "bytes" field of a Tcl_Obj contains invalid data and the type is not tclStringType
User & Date: apnadkarni on 2023-04-22 05:35:07
Changes

  1. icomment:
    I have concerns with this fix. I suspect `TclStringCat` was written the way it was for performance reasons. Here is a simple benchmark.
    
    After your fix:
    
    ```
    % set b [testbigdata bytearray 100000]; string length $b
    100000
    % timerate -calibrate {}
    0.03403821298619367 µs/#-overhead 0.038996 µs/# 50056827 # 25643866 #/sec
    % timerate {string cat $b $b $b $b $b $b $b $b $b $b}
    866.686 µs/# 1154 # 1153.8 #/sec 1000.156 net-ms
    % set b [testbigdata string 100000]; string length $b
    100000
    % timerate {string cat $b $b $b $b $b $b $b $b $b $b}
    730.523 µs/# 1369 # 1368.9 #/sec 1000.086 net-ms
    ```
    
    Here's the same with the commit prior to your fix.
    
    ```
    % set b [testbigdata bytearray 100000]; string length $b
    100000
    % timerate -calibrate {}
    0.0332670332449772 µs/#-overhead 0.036267 µs/# 53823298 # 27573410 #/sec
    % timerate {string cat $b $b $b $b $b $b $b $b $b $b}
    28.1215 µs/# 35519 # 35560.0 #/sec 998.846 net-ms
    % set b [testbigdata string 100000]; string length $b
    100000
    % timerate {string cat $b $b $b $b $b $b $b $b $b $b}
    31.6985 µs/# 31515 # 31547.2 #/sec 998.979 net-ms
    ```
    
    That difference is not to be dismissed. Moreover, it does not even take into account that Unicode strings will be shimmered, possibly impacting performance of further calls.
    
    Correctness obviously trumps performance. However, here it seems it would be worthwhile to fix TclStringCat rather than throw it all away. It is also not entirely clear to me what it means that Tcl is not consistent on invalid input data and whether that needs correcting.
    
  2. login: "apnadkarni"
  3. mimetype: "text/x-markdown"
  4. status changed to: "Open"