FileStream performance guidelines #74405
Replies: 5 comments 4 replies
-
@dotnet/area-system-io |
Beta Was this translation helpful? Give feedback.
-
Not an answer but I've had a lot of success using the new Random Access class instead of trying to guess the best way to get FileStream to buffer. I also found that the Sync overloads were a bit faster than the Async versions, but that gets tricker if your workload is processing a lot of concurrent requests. |
Beta Was this translation helpful? Give feedback.
-
Ok I'm in the process of doing benchmarks with random files on my machine, and this is what I've found for reading files sequentially into a 16 KiB span:
Conclusions:
If someone else could confirm these sort of figures are accurate, that would be greatly appreciated. I'm inexperienced with benchmarking. Now I have to do writing to files. |
Beta Was this translation helpful? Give feedback.
-
Managed to find this PDF. There's also a video. Both by @adamsitnik. Preallocating for writing seems to do very little in my benchmarks, but increasing the user buffer from 16 KiB to 64 KiB for reading makes a big difference, especially with large files. |
Beta Was this translation helpful? Give feedback.
-
I recently discover that for network shares large buffer can help improve perfomance. Network access is not covered with any tests, but filestreams sometimes can access files on network shares |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Back in 2021, there was a .NET blog post asking whether people were interested in reading .NET File IO performance guidelines. Several people expressed an interest in the comments, and I'm also interested.
bufferSize
, preallocation,SequentialScan
vsRandomAccess
,SetLength
, and so on). I'm not interested in async but others might be.Beta Was this translation helpful? Give feedback.
All reactions