Skip to content

[REQ] [swift5] Reuse URLSessions for requests #8562

@fl034

Description

@fl034

Is your feature request related to a problem? Please describe.

After doing a little research on best practices for URLSession, I stumbled upon this: https://developer.apple.com/videos/play/wwdc2018/714/?time=1646

Now let's see how using fewer URLSession objects can help reduce latency.
All the benefits of connections we use that we just discussed in the previous slides are applicable only if you use the same URLSession object to create your tasks.
It's also important to know that every URLSession object has a connection pool and when you create multiple of these URLSession objects, you don't get any benefit of connection to use.
It's also important to note that the URLSession objects are fairly expensive to create and have a non-trivial memory footprint.

Describe the solution you'd like

  • I'd suggest having a dictionary of [Configuration: URLSession] that will return you an existing session object for your configuration.
  • Configuration must be a hash of URLSessionConfiguration, and optional URLSessionDelegate and OperationQueue as you can initialize your URLSession with those parameters.

Describe alternatives you've considered

  • We could leave it as it is now, since you can achieve the same thing by subclassing the request builder.
    • Also, possible gains may not be noticeable since today's hardware is extremely fast.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions