The reason for this is because rawWrite calls flush, not once, but twice every
time you call it, on the underlying file. This is absolutely absurd, and is a
massive performance bottleneck, especially when it's not needed because the
file may very well have already been opened for writing in binary mode to begin
with. In this particular example, it's flushing to disk every 3 bytes.
Comment #2 by bugzilla — 2019-12-06T13:42:06Z
Just a note: I don't know, if this has also been an issue using linux, but nowadays it works on linux.
Comment #3 by schveiguy — 2020-07-27T15:16:10Z
Just was doing some development and found this same bug. This is absolutely unnecessary, especially if the file is already open in binary mode. We currently don't store what mode the file is in, but we absolutely could (we are allocating a heap struct for this, no reason we can't store that). And only switch if necessary.
This should be an easy change and I'm kind of surprised this has been open for so long.
Comment #4 by dlang-bot — 2020-08-13T06:45:36Z
@canopyofstars created dlang/phobos pull request #7590 "Fix issue 7033: File.rawWrite is slow on Windows" fixing this issue:
- Fix issue 7033
https://github.com/dlang/phobos/pull/7590
Comment #5 by dlang-bot — 2020-08-15T10:07:44Z
dlang/phobos pull request #7590 "Fix issue 7033: File.rawWrite is slow on Windows" was merged into master:
- 8643ecad370508f6adf7ba2a34eee1924e47a2f7 by starcanopy:
Fix issue 7033
https://github.com/dlang/phobos/pull/7590