[ 
https://issues.apache.org/jira/browse/ARROW-4717?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16800385#comment-16800385
 ] 

Jorgen Thelin commented on ARROW-4717:
--------------------------------------

I took a quick look at this, and mostly it is just a straight-forward 
s/Task/ValueTask/

However, the biggest impediment to making this change be most impactful is that 
a "Span-friendly" overload for the C# *System.IO.Stream.WriteAsync* method -- 
which directly handles ReadOnlyMemory<T> (without requiring any copying to 
intermediate byte[] buffer) and returns ValueTask (no heap alloc) -- is only 
available in *.NET Core 2.1* and later.

[Stream.WriteAsync(ReadOnlyMemory<Byte>, 
CancellationToken)|https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.writeasync?view=netcore-2.1#System_IO_Stream_WriteAsync_System_ReadOnlyMemory_System_Byte__System_Threading_CancellationToken_]

Currently the C# Apache.Arrow library here is built for both .NET Core 2.1 and 
.NET Standard 1.3.

How important is it to maintain compatibility with .NET Standard 1.3?

The *ArrowStreamWriter.WriteBufferAsync* function is directly on the hot-path 
for all writes, so switching to using zero-copy memory buffers and zero return 
object heap allocation (which needs .NET Core 2.1+) should make a big 
performance improvement.

Thoughts?

> [C#] Consider exposing ValueTask instead of Task
> ------------------------------------------------
>
>                 Key: ARROW-4717
>                 URL: https://issues.apache.org/jira/browse/ARROW-4717
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: C#
>            Reporter: Eric Erhardt
>            Priority: Major
>
> See [https://github.com/apache/arrow/pull/3736#pullrequestreview-207169204] 
> for the discussion and 
> [https://devblogs.microsoft.com/dotnet/understanding-the-whys-whats-and-whens-of-valuetask/]
>  for the reasoning.
> Using `Task<T>` in public API requires that a new Task instance be allocated 
> on every call. When returning synchronously, using ValueTask will allow the 
> method to not allocate.
> In order to do this, we will need to take a new dependency on  
> {{System.Threading.Tasks.Extensions}} NuGet package.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to