Skip to content

Commit 3b6f721

Browse files
committed
FileOpenMode default changes to Throughput
1 parent 8f91450 commit 3b6f721

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ When a string is needed, you can convert `ReadOnlyMemory<char>` to a string usin
117117
Similar to `StreamReader`, `Utf8StreamReader` has the ability to open a `FileStream` by accepting a `string path`.
118118

119119
```csharp
120-
public Utf8StreamReader(string path, FileOpenMode fileOpenMode = FileOpenMode.Scalability)
121-
public Utf8StreamReader(string path, int bufferSize, FileOpenMode fileOpenMode = FileOpenMode.Scalability)
120+
public Utf8StreamReader(string path, FileOpenMode fileOpenMode = FileOpenMode.Throughput)
121+
public Utf8StreamReader(string path, int bufferSize, FileOpenMode fileOpenMode = FileOpenMode.Throughput)
122122
public Utf8StreamReader(string path, FileStreamOptions options)
123123
public Utf8StreamReader(string path, FileStreamOptions options, int bufferSize)
124124
```
@@ -158,7 +158,7 @@ In a Windows environment, the table in the [IO section of the Performance Improv
158158

159159
By setting `Utf8StreamReader` to `FileOpenMode.Scalability`, true async I/O is enabled and scalability is prioritized. If set to `FileOpenMode.Throughput`, it internally becomes sync-over-async and consumes the ThreadPool, but reduces the overhead of asynchronous I/O and improves throughput.
160160

161-
If frequently executed within a server application, setting it to `Scalability`, and for batch applications, setting it to `Throughput` will likely yield the best performance characteristics. The default is `Scalability`.
161+
If frequently executed within a server application, setting it to `Scalability`, and for batch applications, setting it to `Throughput` will likely yield the best performance characteristics. The default is `Throughput`.
162162

163163
In `Utf8StreamReader`, by carefully adjusting the buffer size on the `Utf8StreamReader` side, the performance difference is minimized. Please refer to the above benchmark results image for specific values.
164164

src/Utf8StreamReader/Utf8StreamReader.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,18 @@ public Utf8StreamReader(Stream stream, int bufferSize, bool leaveOpen)
6262
this.leaveOpen = leaveOpen;
6363
}
6464

65-
public Utf8StreamReader(string path, FileOpenMode fileOpenMode = FileOpenMode.Scalability)
65+
public Utf8StreamReader(string path, FileOpenMode fileOpenMode = FileOpenMode.Throughput)
6666
: this(path, DefaultBufferSize, fileOpenMode)
6767
{
6868
}
6969

70-
public Utf8StreamReader(string path, int bufferSize, FileOpenMode fileOpenMode = FileOpenMode.Scalability)
70+
public Utf8StreamReader(string path, int bufferSize, FileOpenMode fileOpenMode = FileOpenMode.Throughput)
7171
: this(OpenPath(path, fileOpenMode), bufferSize, leaveOpen: false)
7272
{
7373
}
7474

75-
static FileStream OpenPath(string path, FileOpenMode fileOpenMode = FileOpenMode.Scalability)
75+
static FileStream OpenPath(string path, FileOpenMode fileOpenMode = FileOpenMode.Throughput)
7676
{
77-
// useAsync:1 + bufferSize 1 chooses internal FileStreamStrategy to AsyncWindowsFileStreamStrategy(in windows)
78-
// but bufferSize larger than 1, wrapped strategy with BufferedFileStreamStrategy, it is unnecessary in ReadLine.
7977
var fileOptions = (fileOpenMode == FileOpenMode.Scalability)
8078
? (FileOptions.SequentialScan | FileOptions.Asynchronous)
8179
: FileOptions.SequentialScan;

0 commit comments

Comments
 (0)