AddictedCS commented on issue #933:
URL: https://github.com/apache/lucenenet/issues/933#issuecomment-2018691127

   Changing to `file.Flush(flushToDisk: false);` may not be such a bad idea 
after all. I understand the implications (no ACID guarantees), but up until 
.NET 8 they weren't either. 
   
   Just to add as an example, the vast majority of developers use the Dispose 
method to ensure the stream is closed and flushed, and by default, `Dispose` 
uses `Flush(false)`.
   
   Here is an example of the modified benchmark (I've removed the 
`Flush(true)`, method leaving the responsibility to close and flush the stream 
to `Dispose` method:
   
   ```csharp
       private static int WriteData(byte[] buffer, int bufferSize)
       {
           using var stream = 
               new FileStream(
                   path: Path.Combine("test_dir", $"test.{buffer.Length}.bin"),
                   mode: FileMode.OpenOrCreate,
                   access: FileAccess.Write,
                   share: FileShare.ReadWrite,
                   bufferSize: bufferSize);
           stream.Write(buffer, 0, buffer.Length);
           // stream.Flush(flushToDisk: true);
           return buffer.Length;
       }
   ```
   The results are so much faster now, both .NET 7 and 8 showing great 
performance.
   
   ```
   
   BenchmarkDotNet v0.13.12, macOS Sonoma 14.4 (23E214) [Darwin 23.4.0]
   Apple M2 Max, 1 CPU, 12 logical and 12 physical cores
   .NET SDK 8.0.203
     [Host]   : .NET 8.0.3 (8.0.324.11423), Arm64 RyuJIT AdvSIMD
     .NET 7.0 : .NET 7.0.5 (7.0.523.17405), Arm64 RyuJIT AdvSIMD
     .NET 8.0 : .NET 8.0.3 (8.0.324.11423), Arm64 RyuJIT AdvSIMD
   
   Server=True  
   
   | Method      | Job      | Runtime  | PayloadSize | BufferSize | Mean     | 
Error    | StdDev   | Median   | Ratio | RatioSD |
   |------------ |--------- |--------- |------------ |----------- 
|---------:|---------:|---------:|---------:|------:|--------:|
   | WriteStream | .NET 7.0 | .NET 7.0 | 512         | 1024       | 26.65 μs | 
0.506 μs | 0.449 μs | 26.53 μs |  1.00 |    0.00 |
   | WriteStream | .NET 8.0 | .NET 8.0 | 512         | 1024       | 27.52 μs | 
0.545 μs | 1.407 μs | 26.86 μs |  1.06 |    0.08 |
   |             |          |          |             |            |          |  
        |          |          |       |         |
   | WriteStream | .NET 7.0 | .NET 7.0 | 512         | 4096       | 27.55 μs | 
0.466 μs | 0.389 μs | 27.48 μs |  1.00 |    0.00 |
   | WriteStream | .NET 8.0 | .NET 8.0 | 512         | 4096       | 26.86 μs | 
0.454 μs | 0.486 μs | 26.83 μs |  0.97 |    0.02 |
   |             |          |          |             |            |          |  
        |          |          |       |         |
   | WriteStream | .NET 7.0 | .NET 7.0 | 1024        | 1024       | 26.10 μs | 
0.500 μs | 0.513 μs | 26.28 μs |  1.00 |    0.00 |
   | WriteStream | .NET 8.0 | .NET 8.0 | 1024        | 1024       | 25.85 μs | 
0.511 μs | 1.121 μs | 26.00 μs |  0.96 |    0.07 |
   |             |          |          |             |            |          |  
        |          |          |       |         |
   | WriteStream | .NET 7.0 | .NET 7.0 | 1024        | 4096       | 27.15 μs | 
0.461 μs | 0.616 μs | 27.03 μs |  1.00 |    0.00 |
   | WriteStream | .NET 8.0 | .NET 8.0 | 1024        | 4096       | 26.87 μs | 
0.425 μs | 0.355 μs | 26.89 μs |  0.99 |    0.04 |
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to