ReadAllBytes is creating a FileStream with the default buffer size of 4K. Since we've already allocated a byte array large enough to hold the entire file, the internal buffer allocated in FileStream is pure overhead, both for the allocation itself and also for the extra copy of data through the buffer.
This commit fixes this simply by explicitly setting the bufferSize to 1. FileStream lazily-allocates the buffer, only creating and using it if it needs it. If a read comes in for a size greater than or equal to the bufferSize, it'll skip the buffer. So, previously, when reading a file > 4K in size, the buffer would be avoided; now it's also avoided for files <= 4K in size.
A microbenchmark repeatedly caling ReadAllBytes showed that with this fix the number of gen0 GCs caused by its usage dropped anywhere from 0-10x, depending on the size of the file being read. Throughput improved by a few percentage points as well.
(Note that I also tried this same change for WriteAllBytes. While it did have a similar effect on gen0 GCs, it caused a surprising regression in throughput, upwards of 20%, and I did not further dig into why. I also noticed that at the moment FileStream in .NET Core is defaulting to useAsync=true, which is different from the desktop and doesn't make much sense for {Read/Write}AllBytes; if that default remains the same, we should explicitly set useAsync=false for these methods.)
Commit migrated from https://github.com/dotnet/corefx/commit/7f84dfbc13bba30caf8938ca1edd565ba2f42c62
We control the targeting centrally and we shouldn't be retargeting
from VS. With the new support for running tests on F5, it is best
to be able to see and edit the command line in the property pages.
Before this, we had an arbitrary mix of the guids being present or
not anyhow. At some point, if we need to set it, we can put it back
across the board and hopefully by then we'll have proper VS test
integration anyhow.
Commit migrated from https://github.com/dotnet/corefx/commit/da9663498c4f5e6bb663e97531afc48964ffbdd0
This commit removes several unnecessary char-related allocations in System.IO.FileSystem. Most of them stemmed from appending the DirectorySeparatorChar to a string, which results in the compiler using String.Concat(..., object) for the concatenation, which means the char gets boxed. Others stemmed from array allocations that could have been cached, e.g. allocating an array for the directory separator chars on each call to TrimEnd.
In fixing these, I also noticed and fixed a few places where duplicated logic could be replaced with a call to IsDirectoryChar.
Commit migrated from https://github.com/dotnet/corefx/commit/b5d327ac0ad50488c801b716b69521be6a6720c9
The System.Runtime.Serialization namespace isn't defined in any of the
NuGet packages and is not used in the project, so it can be removed.
The System.IO.FileSystem tests were missing a reference to
System.Runtime.Handles in packages.config (SafeHandle is defined there).
This fixes compilation errors on the Mono compiler.
Commit migrated from https://github.com/dotnet/corefx/commit/11f161176d4b1823f47d35d651a027a892f4e1ad
When System.IO.FileSystem was added to the repo, changes made to SafeFileHandle did not migrate with it. There was also a file reference missing from the .csproj file. Both of these broke the Unix build. This change just brings those back in sync.
Commit migrated from https://github.com/dotnet/corefx/commit/49ea84c45b466d90ef4490a49976ea7b498287a0
TaskHelpers.cs is a temporary stop-gap for assemblies that don't yet depend on the latest System.Threading.Tasks contract. This change removes the dependency for those assemblies that do, changing them to use the Task.CompletedTask, Task.FromCanceled, and Task.FromException members on Task instead of the corresponding workarounds on TaskHelpers. This file should eventually go away entirely.
Commit migrated from https://github.com/dotnet/corefx/commit/325e24de73b86c2b1f920109afe06faedb42b3d8