dotnet / dotnet/macios

Unnecessary delay in NSUrlSessionDataTaskStream that decreases NSUrlSessionHandler performance.

Open
#10,113 1 comment 0 reactions 0 assignees View on GitHub
enhancement networking
Dominant language
C#
Stars
2.9k
Forks
576
Avg merge
2d 12h
Merged PRs (30d)
123

Description

### Steps to Reproduce

1. Create HttpClient using **NSUrlSessionHandler** to make http requests.
2. Get a resource ~1kb size using _SendAsync_ method with option _HttpCompletionOption.ResponseHeadersRead_
3. Read content as stream from the response message. (message.Content.ReadAsStreamAsync();)
4. Read from the stream using 8kb blocks of data.

### Expected Behavior

Works as fast as when default HttpClientHandler is used. No unnecessary delays while reading from the stream.

### Actual Behavior

In the most cases it will hit this delay in **NSUrlSessionDataTaskStream** https://github.com/xamarin/xamarin-macios/blob/main/src/Foundation/NSUrlSessionHandler.cs#L1044 if we start reading from the stream immediately after response message was received since no data has been added yet with this method https://github.com/xamarin/xamarin-macios/blob/main/src/Foundation/NSUrlSessionHandler.cs#L994

As the result total reading time from NSUrlSessionDataTaskStream for small resources becomes ~50 ms slower then it should be.

If resource content is large the delay can also hit several times more if we are reading from the stream faster then receiving data.

### Environment
IPhone Simulator, IPhone device.

```
```

### Build Logs

### Example Project (If Possible)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.