Skip to content
Tcl Source Code History Of Ticket 605074ede5ccc8bc3fdd67e339575c45bd1a1522
Login

History Of Ticket 605074ede5ccc8bc3fdd67e339575c45bd1a1522

Artifacts Associated With Ticket 605074ede5ccc8bc3fdd67e339575c45bd1a1522

  1. Ticket change [2f279ac8ca] (rid 134704) by damkerngt on 2013-10-16 21:09:42:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized 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 initialized to: "8.4, 8.5, 8.6"
    6. is_private initialized to: "0"
    7. login: "damkerngt"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "5b861da73eb25bd34a919c8675a3381d9132b73b"
    10. resolution initialized to: "None"
    11. severity initialized to: "Important"
    12. status initialized to: "Open"
    13. submitter initialized to: "damkerngt"
    14. subsystem initialized to: "16. Commands A-H"
    15. title initialized to: "New sub-command: file utime"
    16. type initialized to: "RFE"
  2. Ticket change [1f7c0ac0c2] (rid 134748) by dgp on 2013-10-17 18:15:09:

    1. assignee changed to: "dkf"
    2. icomment: "Passing to dkf for initial review."
    3. login: "dgp"
    4. mimetype: "text/plain"
  3. Ticket change [f810d775cb] (rid 134749) by dkf on 2013-10-17 19:04:06:

    1. icomment:
      I'm a little slow at reviewing things right now; work has been <i>exceptionally</i> demanding for the past few weeks.<p>That said, I could well believe that there's an issue with all those stat() calls.
      (XREF: <a href="/tcl/timeline?r=damkerngt-file-utime"><tt>damkerngt-file-utime</tt></a>)<p>Priority boosted; patch exists.
      <blockquote><small><b>Point of protocol.</b> Push new features to their own branches. We're a little bureaucratic about what things go in a release (which makes sense especially when you've got something that interacts trickily with other things, as some features <i>definitely</i> do!) so committing to a branch makes it much clearer what's going on. It also means that if there's a mistake on some relatively obscure platform (or just one that you happen to not have, like a weird commercial Unix) nobody gets too upset...</small><p><small>Cheers!</small></blockquote>
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. priority changed to: "8"
    5. username: "dkf"
  4. Ticket change [2f2bcf4c32] (rid 134766) by damkerngt on 2013-10-18 14:06:07:

    1. icomment:
      I believe I can pinpoint the pattern that could cause this stat() problem now.
      
      The <strong>pre-condition</strong>, which is very important is:
      We need to set <code>[file mtime]</code> on a massive number of files that distributed among several sub-directories.
      The number of files is important. For example, 10,000 files might not cause any penalty, 50,000 files does.
      Directory structure must be realistic. Updating mtime of 50,000 files in a single directory might not cause the penalty, but 50,000 files in 5,000 directories does. (Hence, the benchmark script tries to imitate such a structure.)
      
      
      <strong>Additional conditions:</strong>
      The penalty can occur on both Linux and Windows (I have no Mac OS X to test at the moment).
      
      On Linux (I tested it on Ubuntu), if there was massive disk writes just before or during the moment we set <code>[file mtime]</code>, the penalty will occur. (A task that could be done in less than 3 seconds went up to 47 seconds.) If not, calling or not calling GetStatBuf() does not matter.
      
      On Windows, the penalty seems to depend on both whether we just have massive disk writes and the remaining available memory. The remaining available memory seems to have more impact. The strange thing is that you don't need to have really low memory in order to observe the huge penalty, just have it used up about 2/3 (i.e. 1/3 of your memory left) would do. (A task that could be done in 25 seconds went up to 125 seconds.)
      
      Please find the benchmark code in [http://paste.tclers.tk/2926].
      
    2. login: "damkerngt"
    3. mimetype: "text/x-fossil-wiki"