Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #8562
Closed
Open
Issue created Jan 28, 2021 by Administrator@rootContributor

[REQ] [swift5] Reuse URLSessions for requests

Created by: 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

  • the client with Alamofire option doesn't reuse url sessions either
    • here we're creating a new SessionManager object for each request, which under the hood of Alamofire 4.x, creates a new URLSession: https://github.com/OpenAPITools/openapi-generator/blob/150e24dc553a8ea5230ffb938ed3e6020e972faa/modules/openapi-generator/src/main/resources/swift4/AlamofireImplementations.mustache#L64
Assignee
Assign to
Time tracking