D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21594 - Writing object files should be read-then-write
Summary: Writing object files should be read-then-write
Status: RESOLVED DUPLICATE of issue 21593
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-30 13:56 UTC by Andrei Alexandrescu
Modified: 2021-01-30 13:57 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrei Alexandrescu 2021-01-30 13:56:01 UTC
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 1 Andrei Alexandrescu 2021-01-30 13:57:43 UTC

*** This issue has been marked as a duplicate of issue 21593 ***