Files
dotnet-runtime/src/libraries/System.IO.FileSystem
stephentoub 28a4e51856 Use PreallocatedOverlapped in FileStream
When using async operations on FileStream, each operation ends up allocating several objects.  By using a PreallocatedOverlapped, we can avoid the majority of those allocations, as well as avoid having to pin/unpin a buffer on each request.

This commit adds an optimization to FileStream that kicks in for the common case when:
- The buffer provided to ReadAsync/WriteAsync is smaller than the size of the FileStream's buffer, such that the FileStream's buffer is used.  And when...
- Operations are not scheduled to run concurrently.

When those conditions are met, we use a PreallocatedOverlapped for the operation to avoid a ThreadPoolBoundHandleOverlapped, IOCompletionCallback, and _IOCompletionCallback getting allocated for each operation.  This reduces the bytes allocated per operation by ~50% and the number of objects allocated by ~60%.  It also saves having to pin/unpin the buffer on each operation.

When those conditions aren't met, we simply use the same code that's used today.


Commit migrated from https://github.com/dotnet/corefx/commit/c01617841be8b5087ed37f64bb2395afc722e549
2016-01-25 20:35:01 -05:00
..
2016-01-23 11:36:29 -05:00