www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - An easy phobos i/o bug to fix

reply Steven Schveighoffer <schveiguy gmail.com> writes:
If anyone is using windows and std.stdio.File.rawWrite, it's insanely 
slow. And it's an easy fix. See 
https://issues.dlang.org/show_bug.cgi?id=7033

I don't use Windows, so I probably won't get around to fixing this. But 
ping me if you make a PR, I will review it.

-Steve
Jul 27 2020
next sibling parent reply starcanopy <starcanopy protonmail.com> writes:
On Monday, 27 July 2020 at 15:19:44 UTC, Steven Schveighoffer 
wrote:
 If anyone is using windows and std.stdio.File.rawWrite, it's 
 insanely slow. And it's an easy fix. See 
 https://issues.dlang.org/show_bug.cgi?id=7033

 I don't use Windows, so I probably won't get around to fixing 
 this. But ping me if you make a PR, I will review it.

 -Steve
So, upon opening a File, save the mode into a field, and only execute the current behavior iff the mode isn't binary?
Jul 28 2020
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 7/28/20 7:24 PM, starcanopy wrote:
 On Monday, 27 July 2020 at 15:19:44 UTC, Steven Schveighoffer wrote:
 If anyone is using windows and std.stdio.File.rawWrite, it's insanely 
 slow. And it's an easy fix. See 
 https://issues.dlang.org/show_bug.cgi?id=7033

 I don't use Windows, so I probably won't get around to fixing this. 
 But ping me if you make a PR, I will review it.
So, upon opening a File, save the mode into a field, and only execute the current behavior iff the mode isn't binary?
Almost! I was thinking to store the current mode, and then only change the mode when needed, including the required flush. This way, subsequent rawWrite calls are less expensive, even if it was open originally for text mode. -Steve
Jul 28 2020
parent reply starcanopy <starcanopy protonmail.com> writes:
On Wednesday, 29 July 2020 at 02:18:44 UTC, Steven Schveighoffer 
wrote:
 On 7/28/20 7:24 PM, starcanopy wrote:
 On Monday, 27 July 2020 at 15:19:44 UTC, Steven Schveighoffer 
 wrote:
 If anyone is using windows and std.stdio.File.rawWrite, it's 
 insanely slow. And it's an easy fix. See 
 https://issues.dlang.org/show_bug.cgi?id=7033

 I don't use Windows, so I probably won't get around to fixing 
 this. But ping me if you make a PR, I will review it.
So, upon opening a File, save the mode into a field, and only execute the current behavior iff the mode isn't binary?
Almost! I was thinking to store the current mode, and then only change the mode when needed, including the required flush. This way, subsequent rawWrite calls are less expensive, even if it was open originally for text mode. -Steve
Looks like the contents of the Windows' version needs to be put into an if statement if I'm correctly following you. version (Windows) { import std.algorithm: canFind; /* currMode is a member of File I'd imagine, unless the value being assigned to currMode is normalized, canFind or something similar would be preferable over exhaustive checking. */ if (!currMode.canFind("b")) { // current behavior } } // write
Jul 28 2020
parent starcanopy <starcanopy protonmail.com> writes:
On Wednesday, 29 July 2020 at 03:08:43 UTC, starcanopy wrote:
 Looks like the contents of the Windows' version needs to be put 
 into an if statement if I'm correctly following you.

 version (Windows)
 {
     import std.algorithm: canFind;

     /* currMode is a member of File
     I'd imagine, unless the value being assigned to currMode is 
 normalized, canFind or something similar would be preferable 
 over exhaustive checking. */
     if (!currMode.canFind("b"))
     {
         // current behavior
     }
 }

 // write
You could also just have a boolean member, e.g. binaryMode, present in only the Windows compilation that is true iff the mode in which the file was opened specified a binary mode.
Jul 28 2020
prev sibling parent reply Avrina <avrina12309412342 gmail.com> writes:
On Monday, 27 July 2020 at 15:19:44 UTC, Steven Schveighoffer 
wrote:
 I don't use Windows, so I probably won't get around to fixing 
 this. But ping me if you make a PR, I will review it.

 -Steve
 This should be an easy change and I'm kind of surprised this 
 has been open for so long.
This is the reason why.
Jul 28 2020
parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 7/28/20 7:44 PM, Avrina wrote:
 On Monday, 27 July 2020 at 15:19:44 UTC, Steven Schveighoffer wrote:
 I don't use Windows, so I probably won't get around to fixing this. 
 But ping me if you make a PR, I will review it.
 
 
 This should be an easy change and I'm kind of surprised this has been 
 open for so long.
This is the reason why.
Because I don't use Windows? I'm sure there are a lot who do. Perhaps they don't use rawWrite very much? I would say the likely reason is because people who care about performance don't use std.stdio ;) In any case, it's not a good excuse for such a horrendous performance bug to be there for so long. Ironically, rawWrite should be as fast as possible because you are not rewriting newlines, but instead it eliminates all buffering. -Steve
Jul 28 2020