Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 2f279ac8cad57b67fe6a718fb4608e903ffe438d
Ticket: 605074ede5ccc8bc3fdd67e339575c45bd1a1522
New sub-command: file utime
User & Date: damkerngt on 2013-10-16 21:09:42
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    Proposal:
    A new command [file utime] for fast file's atime/mtime update
    Usage: file utime FILENAME ATIME MTIME
    
    Background:
    I wrote a small Tcl script that calls a huge number of [file mtime]. To my surprise, I found the script run significantly slower than Python implementation. Even worse, I found that calling [exec touch -d [clock format $mtime -format] $file] can sometimes be faster than [file mtime $file $mtime].
    
    Here are some benchmarks on my Windows XP. Please note that this poor performance occurs only when we update a large number of files consecutively, not in an unrealistic test such as [time {file mtime $file $mtime} 10000]. A quick test on Ubuntu resulted in similar poor performance.
    
    Task: update mtime of about 7500 files
    Tcl 8.4.5, using [file mtime]: 127 seconds
    Tcl 8.4.5, using [exec touch]: 123 seconds
    Tcl 8.5.12, using [file mtime]: 43 seconds
    Tcl 8.5.12, using [exec touch]: 126 seconds
    Tcl 8.6.0, using [file mtime]: 56 seconds
    Tcl 8.6.0, using [exec touch]: 124 seconds
    Python 2.7.3, using os,utime(): 4 seconds
    
    Being curious, I took Tcl 8.5.11 source code, hacked the file generic/tclCmdAH.c to not to call those GetStatBuf() before and after calling Tcl_FSUtime(). The result:
    
    Tcl 8.5.11 (hacked [file mtime]): 7 seconds
    
    which is a big improvement. This also indicates that the I/O bottleneck lies in stat(). Hence my proposal.
    
    Rationale:
    At first, I was tempted to suggest to remove the two GetStatBuf() calls in [file mtime] implementation. But according to Tcl's documentation, [file mtime], with 3 or 4 arguments, returns mtime in both cases. So we need to GetStatBuf() after Tcl_FSUtime(). And since Tcl_FSUtime() needs both atime and mtime, we need GetStatBuf() to retrieve atime before setting mtime anyway, so we can neither remove the GetStatBuf() before nor after the Tcl_FSUtime() call.
    
    That would left us with an underperformed [file mtime] in an I/O intensive situation. To allow performance improvement while still keeping backward compatibility, a new sub-command [file utime] (named after Tcl's existing internal function Tcl_FSUtime) seems to be a good choice.
    
  5. foundin changed to: "8.4, 8.5, 8.6"
  6. is_private changed to: "0"
  7. login: "damkerngt"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "5b861da73eb25bd34a919c8675a3381d9132b73b"
  10. resolution changed to: "None"
  11. severity changed to: "Important"
  12. status changed to: "Open"
  13. submitter changed to: "damkerngt"
  14. subsystem changed to: "16. Commands A-H"
  15. title changed to: "New sub-command: file utime"
  16. type changed to: "RFE"