Uh oh!
There was an error while loading. Please reload this page.
Override ReadAsync and WriteAsync methods on ConsoleStream. - #71971
Conversation
The base Stream class implements these overloads by renting a buffer, creating a ReadWriteTask, and copying data as necessary. Instead, ConsoleStreams can just override these Async methods and synchronously call the underlying OS API. Add tests to verify that input and output console streams behave correctly.
ghost
commented
Jul 11, 2022
Tagging subscribers to this area: @dotnet/area-system-console Issue DetailsThe base Stream class implements these overloads by renting a buffer, Instead, ConsoleStreams can just override these Async methods and synchronously BenchmarkpublicclassConsoleStreamsBenchmark{staticbyte[]_bytes=Encoding.ASCII.GetBytes("Hello, World!");staticStream_stream=Console.OpenStandardOutput();staticNativeMemoryManager_nativeMemoryManager=CreateNativeMemory();privateunsafestaticNativeMemoryManagerCreateNativeMemory(){byte*mem=(byte*)NativeMemory.Alloc((nuint)_bytes.Length);_bytes.AsSpan().CopyTo(newSpan<byte>(mem,_bytes.Length));returnnewNativeMemoryManager(mem,_bytes.Length);}[Benchmark]publicasyncTaskWriteToStream(){await_stream.WriteAsync(_bytes);}[Benchmark]publicasyncTaskWriteNativeMemoryToStream(){await_stream.WriteAsync(_nativeMemoryManager.Memory);}unsafeclassNativeMemoryManager:MemoryManager<byte>{privatebyte*_pointer;privateint_length;internalNativeMemoryManager(byte*pointer,intlength){_pointer=pointer;_length=length;}publicoverrideSpan<byte>GetSpan()=>newSpan<byte>(_pointer,_length);publicoverrideMemoryHandlePin(intelementIndex=0)=>default;publicoverridevoidUnpin(){}protectedoverridevoidDispose(booldisposing){}}}Results
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
eerhardt
commented
Jul 12, 2022
The new "OpenStandardInput" tests need to be skipped on platforms that don't support standard input - like wasm, ios, and android. Fixing... |
adamsitnik
commented
Jul 12, 2022
/azp list |
adamsitnik
commented
Jul 12, 2022
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
eerhardt
commented
Jul 12, 2022
All the |
The base Stream class implements these overloads by renting a buffer,
creating a ReadWriteTask, and copying data as necessary.
Instead, ConsoleStreams can just override these Async methods and synchronously
call the underlying OS API.
Benchmark
Results