Bug 21593 – Only update file time if file to be written already exists

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-01-30T07:57:15Z
Last change time
2021-02-03T17:13:55Z
Keywords
pull
Assigned to
No Owner
Creator
Walter Bright

Comments

Comment #0 by bugzilla — 2021-01-30T07:57:15Z
This is a suggestion from Andrei. Because file writes are so much slower than reads, and because of weak dependency management in build systems, the compiler will often generate the same files again and again. This changes file writes to first see if the file already exists and is identical. If so, it just updates the last written time on that file instead of writing a new one. We discussed whether to "touch" the file or not, and decided if it wasn't touched, it would likely break many build systems.
Comment #1 by dlang-bot — 2021-01-30T07:59:06Z
@WalterBright updated dlang/dmd pull request #12169 "Fix Issue 21593 - Only update file time if file to be written already exists" fixing this issue: - Fix Issue 21593 - Only update file time if file to be written already exists https://github.com/dlang/dmd/pull/12169
Comment #2 by andrei — 2021-01-30T13:57:25Z
Not knowing about this I wrote another one: https://issues.dlang.org/show_bug.cgi?id=21594. Will copy the text from there here, and close that one: It turns out that oftentimes the generated object file for a given .d file is identical to the preexisting one: * The build is triggered by a change in a dependent file that was not material to building this object file (most often) * Only unittests were changed and this is not a unittest build * Only documentation was changed In that case it's worth reading the existing object file (block by block) and comparing it against the object file to be written. * If the object files are different, proceed with writing as usual. * If the file are identical, do NOT overwrite the file. Do touch it to announce to tbe build system that the build has been done. This should be particularly gainful on SSD drives, which are much cheaper to read than to write. Comparison of files should be done block by block, not by slurping the entire object file. This is because once the headers are different all time spent reading the rest of the file is wasted.
Comment #3 by andrei — 2021-01-30T13:57:43Z
*** Issue 21594 has been marked as a duplicate of this issue. ***
Comment #4 by andrei — 2021-01-30T20:49:58Z
Comment #5 by andrei — 2021-01-30T20:57:28Z
Comment #6 by dlang-bot — 2021-02-03T17:13:55Z
dlang/dmd pull request #12169 "Fix Issue 21593 - Only update file time if file to be written already exists" was merged into master: - 61b340226af7948995bced165617651509923860 by Walter Bright: Fix Issue 21593 - Only update file time if file to be written already exists https://github.com/dlang/dmd/pull/12169